From 086179d2c1e5efa1cf651c4db2c18c432ea54675 Mon Sep 17 00:00:00 2001 From: Dwynr Date: Tue, 12 Nov 2024 20:02:49 +0100 Subject: [PATCH] fix: runOnce state saving --- package.json | 2 +- src/index.ts | 4 +++- src/lib/state.ts | 2 ++ src/lib/sync.ts | 50 ++++++++++++++++-------------------------------- 4 files changed, 23 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index d12e187..efc2652 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@filen/sync", - "version": "0.1.77", + "version": "0.1.78", "description": "Filen Sync", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 3dfa08d..2c4be9b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -205,7 +205,9 @@ export class SyncWorker { this.syncs[syncUUID]!.removed = removed if (removed) { - await this.syncs[syncUUID]!.cleanup() + await this.syncs[syncUUID]!.cleanup({ + deleteLocalDbFiles: true + }) this.syncs[syncUUID]!.localFileSystem.ignoredCache.clear() this.syncs[syncUUID]!.remoteFileSystem.ignoredCache.clear() diff --git a/src/lib/state.ts b/src/lib/state.ts index ee1356a..f045832 100644 --- a/src/lib/state.ts +++ b/src/lib/state.ts @@ -320,6 +320,8 @@ export class State { const tmpDestination = pathModule.join(pathModule.dirname(destination), `${uuidv4()}.tmp`) + console.log({ destination, size: Object.keys(record).length, tmpDestination }) + try { // eslint-disable-next-line no-async-promise-executor await new Promise(async (resolve, reject) => { diff --git a/src/lib/sync.ts b/src/lib/sync.ts index 1413669..2fefbff 100644 --- a/src/lib/sync.ts +++ b/src/lib/sync.ts @@ -50,7 +50,6 @@ export class Sync { public excludeDotFiles: boolean public readonly worker: SyncWorker public removed: boolean = false - public saveStateOnNoChanges = true public readonly lock: Lock public taskErrors: TaskError[] = [] public localTrashDisabled: boolean @@ -201,9 +200,12 @@ export class Sync { } } - public async cleanup(): Promise { + public async cleanup({ deleteLocalDbFiles = false }: { deleteLocalDbFiles?: boolean }): Promise { try { - await Promise.all([this.localFileSystem.stopDirectoryWatcher(), this.deleteLocalSyncDbFiles()]) + await Promise.all([ + this.localFileSystem.stopDirectoryWatcher(), + deleteLocalDbFiles ? this.deleteLocalSyncDbFiles() : Promise.resolve() + ]) this.worker.logger.log("info", "Cleanup done", this.syncPair.localPath) } catch (e) { @@ -226,7 +228,9 @@ export class Sync { private async run(): Promise { if (this.removed) { - await this.cleanup() + await this.cleanup({ + deleteLocalDbFiles: true + }) return } @@ -234,7 +238,9 @@ export class Sync { try { if (this.taskErrors.length > 0 || this.localTreeErrors.length > 0) { if (this.worker.runOnce) { - await this.cleanup() + await this.cleanup({ + deleteLocalDbFiles: false + }) return } @@ -281,7 +287,9 @@ export class Sync { if (this.paused) { if (this.worker.runOnce) { - await this.cleanup() + await this.cleanup({ + deleteLocalDbFiles: false + }) return } @@ -382,31 +390,6 @@ export class Sync { }) if (!currentLocalTree.changed && !currentRemoteTree.changed) { - /*if (this.taskErrors.length === 0) { - postMessageToMain({ - type: "cycleSavingStateStarted", - syncPair: this.syncPair - }) - - this.previousLocalTree = currentLocalTree.result - this.previousRemoteTree = currentRemoteTree.result - - // We only save the state once if there are no changes. - // This helps reducing the cpu and disk footprint when there are continuously no changes. - if (this.saveStateOnNoChanges) { - this.saveStateOnNoChanges = false - - await this.state.save() - } - - runGC() - - postMessageToMain({ - type: "cycleSavingStateDone", - syncPair: this.syncPair - }) - }*/ - postMessageToMain({ type: "cycleSuccess", syncPair: this.syncPair @@ -557,7 +540,6 @@ export class Sync { this.previousLocalTree = currentLocalTree.result this.previousRemoteTree = currentRemoteTree.result - this.saveStateOnNoChanges = true await this.state.save() @@ -601,7 +583,9 @@ export class Sync { } } finally { if (this.worker.runOnce || this.removed) { - await this.cleanup() + await this.cleanup({ + deleteLocalDbFiles: this.removed + }) } else { postMessageToMain({ type: "cycleRestarting",