Skip to content

Commit

Permalink
More robust way to resolve initial sync bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zefhemel committed Jul 28, 2023
1 parent fb67cba commit 8a790aa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
9 changes: 7 additions & 2 deletions common/spaces/fallback_space_primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export class FallbackSpacePrimitives implements SpacePrimitives {
e.message,
);
try {
return await this.fallback.readFile(name);
const result = await this.fallback.readFile(name);
return {
data: result.data,
meta: { ...result.meta, neverSync: true },
};
} catch (fallbackError: any) {
console.error("Error during readFile fallback", fallbackError.message);
// Fallback failed, so let's throw the original error
Expand All @@ -44,7 +48,8 @@ export class FallbackSpacePrimitives implements SpacePrimitives {
e.message,
);
try {
return await this.fallback.getFileMeta(name);
const meta = await this.fallback.getFileMeta(name);
return { ...meta, neverSync: true };
} catch (fallbackError) {
console.error(
"Error during getFileMeta fallback",
Expand Down
1 change: 1 addition & 0 deletions common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export type FileMeta = {
contentType: string;
size: number;
perm: "ro" | "rw";
neverSync?: boolean;
} & Record<string, any>;
12 changes: 5 additions & 7 deletions web/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,11 @@ export class Client {
(meta) => fileFilterFn(meta.name),
// Run when a list of files has been retrieved
async () => {
if (await this.syncService?.hasInitialSyncCompleted()) {
await this.loadSettings();
if (typeof this.settings?.spaceIgnore === "string") {
fileFilterFn = gitIgnoreCompiler(this.settings.spaceIgnore).accepts;
} else {
fileFilterFn = () => true;
}
await this.loadSettings();
if (typeof this.settings?.spaceIgnore === "string") {
fileFilterFn = gitIgnoreCompiler(this.settings.spaceIgnore).accepts;
} else {
fileFilterFn = () => true;
}
},
);
Expand Down
20 changes: 10 additions & 10 deletions web/sync_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,6 @@ export class SyncService {

// Syncs a single file
async syncFile(name: string) {
// Reminder: main reason to do this is not accidentally sync files retrieved via fallthrough (remote) and treat them as locally deleted
if (!await this.hasInitialSyncCompleted()) {
console.info(
"Initial sync hasn't happened yet, skipping sync for individual file",
name,
);
return;
}
if (await this.isSyncing()) {
console.log("Already syncing, aborting individual file sync for", name);
return;
Expand All @@ -199,8 +191,16 @@ export class SyncService {
let localHash: number | undefined;
let remoteHash: number | undefined;
try {
localHash =
(await this.localSpacePrimitives.getFileMeta(name)).lastModified;
const localMeta = await this.localSpacePrimitives.getFileMeta(name);
if (localMeta.neverSync) {
console.info(
"File marked as neverSync, skipping sync in this cycle",
name,
);
await this.registerSyncStop();
return;
}
localHash = localMeta.lastModified;
} catch {
// Not present
}
Expand Down

0 comments on commit 8a790aa

Please sign in to comment.