More robust way to resolve initial sync bug
This commit is contained in:
parent
fb67cba6ac
commit
8a790aae9e
@ -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
|
||||
@ -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",
|
||||
|
@ -6,4 +6,5 @@ export type FileMeta = {
|
||||
contentType: string;
|
||||
size: number;
|
||||
perm: "ro" | "rw";
|
||||
neverSync?: boolean;
|
||||
} & Record<string, any>;
|
||||
|
@ -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;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -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;
|
||||
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user