Fix deletion of open file on initial sync
This commit is contained in:
parent
a758446ecd
commit
fb67cba6ac
@ -23,7 +23,7 @@ export class FallbackSpacePrimitives implements SpacePrimitives {
|
|||||||
return await this.primary.readFile(name);
|
return await this.primary.readFile(name);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.info(
|
console.info(
|
||||||
`Could not read file ${name} from primary, trying fallback`,
|
`Could not read file ${name} from primary, trying fallback, primary read error:`,
|
||||||
e.message,
|
e.message,
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
@ -40,7 +40,7 @@ export class FallbackSpacePrimitives implements SpacePrimitives {
|
|||||||
return await this.primary.getFileMeta(name);
|
return await this.primary.getFileMeta(name);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.info(
|
console.info(
|
||||||
`Could not fetch file ${name} metadata from primary, trying fallback`,
|
`Could not fetch file ${name} metadata from primary, trying fallback, primary read error`,
|
||||||
e.message,
|
e.message,
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
|
@ -7,7 +7,7 @@ export type AppEvent =
|
|||||||
| "minieditor:complete"
|
| "minieditor:complete"
|
||||||
| "page:load"
|
| "page:load"
|
||||||
| "editor:init"
|
| "editor:init"
|
||||||
| "editor:pageLoaded"
|
| "editor:pageLoaded" // args: pageName, previousPage, isSynced
|
||||||
| "editor:pageReloaded"
|
| "editor:pageReloaded"
|
||||||
| "editor:pageSaved"
|
| "editor:pageSaved"
|
||||||
| "editor:modeswitch"
|
| "editor:modeswitch"
|
||||||
|
@ -184,7 +184,12 @@ export class Client {
|
|||||||
if (this.system.plugsUpdated) {
|
if (this.system.plugsUpdated) {
|
||||||
// To register new commands, update editor state based on new plugs
|
// To register new commands, update editor state based on new plugs
|
||||||
this.rebuildEditorState();
|
this.rebuildEditorState();
|
||||||
this.dispatchAppEvent("editor:pageLoaded", this.currentPage);
|
this.dispatchAppEvent(
|
||||||
|
"editor:pageLoaded",
|
||||||
|
this.currentPage,
|
||||||
|
undefined,
|
||||||
|
true,
|
||||||
|
);
|
||||||
if (operations) {
|
if (operations) {
|
||||||
// Likely initial sync so let's show visually that we're synced now
|
// Likely initial sync so let's show visually that we're synced now
|
||||||
// this.flashNotification(`Synced ${operations} files`, "info");
|
// this.flashNotification(`Synced ${operations} files`, "info");
|
||||||
@ -299,13 +304,15 @@ export class Client {
|
|||||||
this.system.indexSyscalls,
|
this.system.indexSyscalls,
|
||||||
),
|
),
|
||||||
(meta) => fileFilterFn(meta.name),
|
(meta) => fileFilterFn(meta.name),
|
||||||
|
// Run when a list of files has been retrieved
|
||||||
async () => {
|
async () => {
|
||||||
// Run when a list of files has been retrieved
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -52,9 +52,14 @@ export class SyncService {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
eventHook.addLocalListener("editor:pageLoaded", async (name) => {
|
eventHook.addLocalListener(
|
||||||
await this.syncFile(`${name}.md`);
|
"editor:pageLoaded",
|
||||||
});
|
async (name, _prevPage, isSynced) => {
|
||||||
|
if (!isSynced) {
|
||||||
|
await this.syncFile(`${name}.md`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
eventHook.addLocalListener("editor:pageSaved", async (name) => {
|
eventHook.addLocalListener("editor:pageSaved", async (name) => {
|
||||||
const path = `${name}.md`;
|
const path = `${name}.md`;
|
||||||
@ -158,19 +163,30 @@ export class SyncService {
|
|||||||
snapshot,
|
snapshot,
|
||||||
(path) => this.isSyncCandidate(path),
|
(path) => this.isSyncCandidate(path),
|
||||||
);
|
);
|
||||||
|
await this.saveSnapshot(snapshot);
|
||||||
|
await this.registerSyncStop();
|
||||||
this.eventHook.dispatchEvent("sync:success", operations);
|
this.eventHook.dispatchEvent("sync:success", operations);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
await this.saveSnapshot(snapshot);
|
||||||
|
await this.registerSyncStop();
|
||||||
this.eventHook.dispatchEvent("sync:error", e.message);
|
this.eventHook.dispatchEvent("sync:error", e.message);
|
||||||
console.error("Sync error", e.message);
|
console.error("Sync error", e.message);
|
||||||
}
|
}
|
||||||
await this.saveSnapshot(snapshot);
|
|
||||||
await this.registerSyncStop();
|
|
||||||
return operations;
|
return operations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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");
|
console.log("Already syncing, aborting individual file sync for", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.isSyncCandidate(name)) {
|
if (!this.isSyncCandidate(name)) {
|
||||||
@ -199,7 +215,7 @@ export class SyncService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.spaceSync!.syncFile(snapshot, name, localHash, remoteHash);
|
await this.spaceSync.syncFile(snapshot, name, localHash, remoteHash);
|
||||||
this.eventHook.dispatchEvent("sync:success");
|
this.eventHook.dispatchEvent("sync:success");
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
this.eventHook.dispatchEvent("sync:error", e.message);
|
this.eventHook.dispatchEvent("sync:error", e.message);
|
||||||
|
Loading…
Reference in New Issue
Block a user