More robust way to resolve initial sync bug
This commit is contained in:
@@ -27,7 +27,11 @@ export class FallbackSpacePrimitives implements SpacePrimitives {
|
|||||||
e.message,
|
e.message,
|
||||||
);
|
);
|
||||||
try {
|
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) {
|
} catch (fallbackError: any) {
|
||||||
console.error("Error during readFile fallback", fallbackError.message);
|
console.error("Error during readFile fallback", fallbackError.message);
|
||||||
// Fallback failed, so let's throw the original error
|
// Fallback failed, so let's throw the original error
|
||||||
@@ -44,7 +48,8 @@ export class FallbackSpacePrimitives implements SpacePrimitives {
|
|||||||
e.message,
|
e.message,
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
return await this.fallback.getFileMeta(name);
|
const meta = await this.fallback.getFileMeta(name);
|
||||||
|
return { ...meta, neverSync: true };
|
||||||
} catch (fallbackError) {
|
} catch (fallbackError) {
|
||||||
console.error(
|
console.error(
|
||||||
"Error during getFileMeta fallback",
|
"Error during getFileMeta fallback",
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ export type FileMeta = {
|
|||||||
contentType: string;
|
contentType: string;
|
||||||
size: number;
|
size: number;
|
||||||
perm: "ro" | "rw";
|
perm: "ro" | "rw";
|
||||||
|
neverSync?: boolean;
|
||||||
} & Record<string, any>;
|
} & Record<string, any>;
|
||||||
|
|||||||
@@ -306,14 +306,12 @@ export class Client {
|
|||||||
(meta) => fileFilterFn(meta.name),
|
(meta) => fileFilterFn(meta.name),
|
||||||
// Run when a list of files has been retrieved
|
// Run when a list of files has been retrieved
|
||||||
async () => {
|
async () => {
|
||||||
if (await this.syncService?.hasInitialSyncCompleted()) {
|
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
if (typeof this.settings?.spaceIgnore === "string") {
|
if (typeof this.settings?.spaceIgnore === "string") {
|
||||||
fileFilterFn = gitIgnoreCompiler(this.settings.spaceIgnore).accepts;
|
fileFilterFn = gitIgnoreCompiler(this.settings.spaceIgnore).accepts;
|
||||||
} else {
|
} else {
|
||||||
fileFilterFn = () => true;
|
fileFilterFn = () => true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
+10
-10
@@ -177,14 +177,6 @@ export class SyncService {
|
|||||||
|
|
||||||
// Syncs a single file
|
// Syncs a single file
|
||||||
async syncFile(name: string) {
|
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()) {
|
if (await this.isSyncing()) {
|
||||||
console.log("Already syncing, aborting individual file sync for", name);
|
console.log("Already syncing, aborting individual file sync for", name);
|
||||||
return;
|
return;
|
||||||
@@ -199,8 +191,16 @@ export class SyncService {
|
|||||||
let localHash: number | undefined;
|
let localHash: number | undefined;
|
||||||
let remoteHash: number | undefined;
|
let remoteHash: number | undefined;
|
||||||
try {
|
try {
|
||||||
localHash =
|
const localMeta = await this.localSpacePrimitives.getFileMeta(name);
|
||||||
(await this.localSpacePrimitives.getFileMeta(name)).lastModified;
|
if (localMeta.neverSync) {
|
||||||
|
console.info(
|
||||||
|
"File marked as neverSync, skipping sync in this cycle",
|
||||||
|
name,
|
||||||
|
);
|
||||||
|
await this.registerSyncStop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
localHash = localMeta.lastModified;
|
||||||
} catch {
|
} catch {
|
||||||
// Not present
|
// Not present
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user