From d4bbf795149093312572a3a5ae2c57379aad4363 Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Thu, 29 Sep 2022 16:58:39 +0900 Subject: [PATCH] Fixed: - Fixed a bug about deleting empty directory - Weird behaviour on boot-sequence on mobile devices. --- src/main.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 59a199d..33f0505 100644 --- a/src/main.ts +++ b/src/main.ts @@ -842,6 +842,12 @@ export default class ObsidianLiveSyncPlugin extends Plugin { this.watchedFileEventQueue = []; for (const queue of procs) { const file = queue.args.file; + const key = `file-last-proc-${queue.type}-${file.path}`; + const last = Number(await this.localDatabase.kvDB.get(key) || 0); + if (file instanceof TFile && file.stat.mtime == last) { + Logger(`File has been already scanned on ${queue.type}, skip: ${file.path}`, LOG_LEVEL.VERBOSE); + continue; + } const cache = queue.args.cache; if ((queue.type == "CREATE" || queue.type == "CHANGED") && file instanceof TFile) { await this.updateIntoDB(file, false, cache); @@ -856,6 +862,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin { if (queue.type == "RENAME") { await this.watchVaultRenameAsync(file, queue.args.oldPath); } + if (file instanceof TFile) { + await this.localDatabase.kvDB.set(key, file.stat.mtime); + } } this.refreshStatusText(); }) @@ -1106,7 +1115,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin { } async deleteVaultItem(file: TFile | TFolder) { - if (!this.isTargetFile(file)) return; + if (file instanceof TFile) { + if (!this.isTargetFile(file)) return; + } const dir = file.parent; if (this.settings.trashInsteadDelete) { await this.app.vault.trash(file, false); @@ -1718,7 +1729,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin { await this.pullFile(e, filesStorage, false, null, false); Logger(`Check or pull from db:${e} OK`); } else { - Logger(`entry not found, maybe deleted:${e}`); + Logger(`entry not found, maybe deleted (it is normal behavior):${e}`); } }); }