diff --git a/package.json b/package.json index b92f317..0d0ecde 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@filen/sync", - "version": "0.1.72", + "version": "0.1.73", "description": "Filen Sync", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/lib/deltas.ts b/src/lib/deltas.ts index a3dfb89..e1207be 100644 --- a/src/lib/deltas.ts +++ b/src/lib/deltas.ts @@ -7,6 +7,7 @@ export type Delta = { path: string } & ( | { type: "uploadFile" size: number + md5Hash?: string } | { type: "createRemoteDirectory" @@ -325,19 +326,23 @@ export class Deltas { currentLocalItem && currentLocalItem.type === "file" && normalizeLastModifiedMsForComparison(currentLocalItem.lastModified) > - normalizeLastModifiedMsForComparison(currentRemoteItem.lastModified) && - (await this.sync.localFileSystem.createFileHash({ + normalizeLastModifiedMsForComparison(currentRemoteItem.lastModified) + ) { + const md5Hash = await this.sync.localFileSystem.createFileHash({ relativePath: path, algorithm: "md5" - })) !== this.sync.localFileHashes[currentLocalItem.path] - ) { - deltas.push({ - type: "uploadFile", - path, - size: currentLocalItem.size }) - pathsAdded[path] = true + if (md5Hash !== this.sync.localFileHashes[currentLocalItem.path]) { + deltas.push({ + type: "uploadFile", + path, + size: currentLocalItem.size, + md5Hash + }) + + pathsAdded[path] = true + } } } } diff --git a/src/lib/filesystems/local.ts b/src/lib/filesystems/local.ts index ee6fd1e..b8bad7f 100644 --- a/src/lib/filesystems/local.ts +++ b/src/lib/filesystems/local.ts @@ -747,15 +747,15 @@ export class LocalFileSystem { /** * Upload a local file. - * @date 3/2/2024 - 9:43:58 PM * * @public * @async - * @param {{ relativePath: string }} param0 + * @param {{ relativePath: string, passedMD5Hash?: string }} param0 * @param {string} param0.relativePath + * @param {string} param0.passedMD5Hash * @returns {Promise} */ - public async upload({ relativePath }: { relativePath: string }): Promise { + public async upload({ relativePath, passedMD5Hash }: { relativePath: string; passedMD5Hash?: string }): Promise { const localPath = pathModule.join(this.sync.syncPair.localPath, relativePath) const signalKey = `upload:${relativePath}` const stats = await fs.stat(localPath) @@ -791,12 +791,14 @@ export class LocalFileSystem { throw new Error(`Could not upload ${relativePath}: Parent path not found.`) } - const hash = await this.createFileHash({ - relativePath, - algorithm: "md5" - }) + const md5Hash = passedMD5Hash + ? passedMD5Hash + : await this.createFileHash({ + relativePath, + algorithm: "md5" + }) - this.sync.localFileHashes[relativePath] = hash + this.sync.localFileHashes[relativePath] = md5Hash const item = await this.sync.sdk.cloud().uploadLocalFile({ source: localPath, diff --git a/src/lib/tasks.ts b/src/lib/tasks.ts index 9e5393d..f293278 100644 --- a/src/lib/tasks.ts +++ b/src/lib/tasks.ts @@ -484,7 +484,10 @@ export class Tasks { case "uploadFile": { try { const [, stats] = await Promise.all([ - this.sync.localFileSystem.upload({ relativePath: delta.path }), + this.sync.localFileSystem.upload({ + relativePath: delta.path, + passedMD5Hash: delta.md5Hash + }), fs.stat(pathModule.join(this.sync.syncPair.localPath, delta.path)) ]) const item = this.sync.remoteFileSystem.getDirectoryTreeCache.tree[delta.path]