Basic syncing in the plugin
This commit is contained in:
parent
dfdf1d016b
commit
d088d42a65
1 changed files with 561 additions and 179 deletions
38
plugin/src/sync-operations/sync-locally-deleted-file.ts
Normal file
38
plugin/src/sync-operations/sync-locally-deleted-file.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { Database } from "src/database/database";
|
||||
import { RelativePath } from "src/database/document-metadata";
|
||||
import { Logger } from "src/logger";
|
||||
import { SyncServer } from "src/services/sync_service";
|
||||
import { tryLockDocument, unlockDocument, waitForDocumentLock } from "./locks";
|
||||
|
||||
export async function syncLocallyDeletedFile(
|
||||
database: Database,
|
||||
syncServer: SyncServer,
|
||||
relativePath: RelativePath
|
||||
): Promise<void> {
|
||||
await waitForDocumentLock(relativePath);
|
||||
|
||||
try {
|
||||
const metadata = database.getDocument(relativePath);
|
||||
if (!metadata) {
|
||||
Logger.getInstance().warn(
|
||||
`Document metadata not found for ${relativePath}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await syncServer.delete({
|
||||
documentId: metadata.documentId,
|
||||
relativePath,
|
||||
// We got the event now, so it must have been deleted just now
|
||||
createdDate: new Date(),
|
||||
});
|
||||
|
||||
await database.removeDocument(relativePath);
|
||||
} catch (e) {
|
||||
Logger.getInstance().error(
|
||||
`Failed to sync locally deleted file ${relativePath}: ${e}`
|
||||
);
|
||||
} finally {
|
||||
unlockDocument(relativePath);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue