From 59f951f2b8590a429a0c5ebce190df97bba99993 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Thu, 22 May 2025 16:50:02 +0200 Subject: [PATCH] Fix sync not working if files have been deleted, moved, or renamed --- src/sync-manager.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/sync-manager.ts b/src/sync-manager.ts index 9296dca..da11a5a 100644 --- a/src/sync-manager.ts +++ b/src/sync-manager.ts @@ -700,16 +700,19 @@ export default class SyncManager { type: "delete_local", filePath: filePath, }); + return; } else if ( localFile.lastModified > (remoteFile.deletedAt as number) ) { actions.push({ type: "upload", filePath: filePath }); + return; } } if (!remoteFile.deleted && localFile.deleted) { if (remoteFile.lastModified > (localFile.deletedAt as number)) { actions.push({ type: "download", filePath: filePath }); + return; } else if ( (localFile.deletedAt as number) > remoteFile.lastModified ) { @@ -717,6 +720,7 @@ export default class SyncManager { type: "delete_remote", filePath: filePath, }); + return; } } @@ -724,8 +728,10 @@ export default class SyncManager { // Conflicts are already filtered out so we can make this decision easily if (localSHA !== localFile.sha) { actions.push({ type: "upload", filePath: filePath }); + return; } else { actions.push({ type: "download", filePath: filePath }); + return; } }), ); @@ -784,9 +790,13 @@ export default class SyncManager { * This is the same identical algoritm used by git to calculate * a blob's SHA. * @param filePath normalized path to file - * @returns String containing the file SHA1 + * @returns String containing the file SHA1 or null in case the file doesn't exist */ - async calculateSHA(filePath: string): Promise { + async calculateSHA(filePath: string): Promise { + if (!(await this.vault.adapter.exists(filePath))) { + // The file doesn't exist, can't calculate any SHA + return null; + } const contentBuffer = await this.vault.adapter.readBinary(filePath); const contentBytes = new Uint8Array(contentBuffer); const header = new TextEncoder().encode(`blob ${contentBytes.length}\0`);