@@ -700,32 +700,38 @@ export default class SyncManager {
700700 type : "delete_local" ,
701701 filePath : filePath ,
702702 } ) ;
703+ return ;
703704 } else if (
704705 localFile . lastModified > ( remoteFile . deletedAt as number )
705706 ) {
706707 actions . push ( { type : "upload" , filePath : filePath } ) ;
708+ return ;
707709 }
708710 }
709711
710712 if ( ! remoteFile . deleted && localFile . deleted ) {
711713 if ( remoteFile . lastModified > ( localFile . deletedAt as number ) ) {
712714 actions . push ( { type : "download" , filePath : filePath } ) ;
715+ return ;
713716 } else if (
714717 ( localFile . deletedAt as number ) > remoteFile . lastModified
715718 ) {
716719 actions . push ( {
717720 type : "delete_remote" ,
718721 filePath : filePath ,
719722 } ) ;
723+ return ;
720724 }
721725 }
722726
723727 // For non-deletion cases, if SHAs differ, we just need to check if local changed.
724728 // Conflicts are already filtered out so we can make this decision easily
725729 if ( localSHA !== localFile . sha ) {
726730 actions . push ( { type : "upload" , filePath : filePath } ) ;
731+ return ;
727732 } else {
728733 actions . push ( { type : "download" , filePath : filePath } ) ;
734+ return ;
729735 }
730736 } ) ,
731737 ) ;
@@ -784,9 +790,13 @@ export default class SyncManager {
784790 * This is the same identical algoritm used by git to calculate
785791 * a blob's SHA.
786792 * @param filePath normalized path to file
787- * @returns String containing the file SHA1
793+ * @returns String containing the file SHA1 or null in case the file doesn't exist
788794 */
789- async calculateSHA ( filePath : string ) : Promise < string > {
795+ async calculateSHA ( filePath : string ) : Promise < string | null > {
796+ if ( ! ( await this . vault . adapter . exists ( filePath ) ) ) {
797+ // The file doesn't exist, can't calculate any SHA
798+ return null ;
799+ }
790800 const contentBuffer = await this . vault . adapter . readBinary ( filePath ) ;
791801 const contentBytes = new Uint8Array ( contentBuffer ) ;
792802 const header = new TextEncoder ( ) . encode ( `blob ${ contentBytes . length } \0` ) ;
0 commit comments