From 7b9724f713ce1009d8fc35950a0142d22f8f0a0c Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Tue, 8 Aug 2023 10:42:07 +0100 Subject: [PATCH] Fixed: - Now nested ignore files could be parsed correctly. - The unexpected deletion of hidden files in some cases has been corrected. - Hidden file change is no longer reflected on the device which has made the change itself. --- src/CmdHiddenFileSync.ts | 22 +++++++++++----------- src/lib | 2 +- src/main.ts | 13 +++++++++---- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/CmdHiddenFileSync.ts b/src/CmdHiddenFileSync.ts index f601ae4..b4dd6a6 100644 --- a/src/CmdHiddenFileSync.ts +++ b/src/CmdHiddenFileSync.ts @@ -273,7 +273,7 @@ export class HiddenFileSync extends LiveSyncCommands { if (!filename) continue; if (ignorePatterns.some(e => filename.match(e))) continue; - if (!await this.plugin.isIgnoredByIgnoreFiles(filename)) { + if (await this.plugin.isIgnoredByIgnoreFiles(filename)) { continue } @@ -434,7 +434,7 @@ export class HiddenFileSync extends LiveSyncCommands { } async storeInternalFileToDatabase(file: InternalFileInfo, forceWrite = false) { - if (!await this.plugin.isIgnoredByIgnoreFiles(file.path)) { + if (await this.plugin.isIgnoredByIgnoreFiles(file.path)) { return } const id = await this.path2id(file.path, ICHeader); @@ -498,7 +498,7 @@ export class HiddenFileSync extends LiveSyncCommands { const id = await this.path2id(filename, ICHeader); const prefixedFileName = addPrefix(filename, ICHeader); const mtime = new Date().getTime(); - if (!await this.plugin.isIgnoredByIgnoreFiles(filename)) { + if (await this.plugin.isIgnoredByIgnoreFiles(filename)) { return } await runWithLock("file-" + prefixedFileName, false, async () => { @@ -544,7 +544,7 @@ export class HiddenFileSync extends LiveSyncCommands { async extractInternalFileFromDatabase(filename: FilePath, force = false) { const isExists = await this.app.vault.adapter.exists(filename); const prefixedFileName = addPrefix(filename, ICHeader); - if (!await this.plugin.isIgnoredByIgnoreFiles(filename)) { + if (await this.plugin.isIgnoredByIgnoreFiles(filename)) { return; } return await runWithLock("file-" + prefixedFileName, false, async () => { @@ -568,7 +568,7 @@ export class HiddenFileSync extends LiveSyncCommands { await this.app.vault.adapter.remove(filename); try { //@ts-ignore internalAPI - await app.vault.adapter.reconcileInternalFile(filename); + await this.app.vault.adapter.reconcileInternalFile(filename); } catch (ex) { Logger("Failed to call internal API(reconcileInternalFile)", LOG_LEVEL_VERBOSE); Logger(ex, LOG_LEVEL_VERBOSE); @@ -581,7 +581,7 @@ export class HiddenFileSync extends LiveSyncCommands { await this.app.vault.adapter.writeBinary(filename, base64ToArrayBuffer(fileOnDB.data), { mtime: fileOnDB.mtime, ctime: fileOnDB.ctime }); try { //@ts-ignore internalAPI - await app.vault.adapter.reconcileInternalFile(filename); + await this.app.vault.adapter.reconcileInternalFile(filename); } catch (ex) { Logger("Failed to call internal API(reconcileInternalFile)", LOG_LEVEL_VERBOSE); Logger(ex, LOG_LEVEL_VERBOSE); @@ -591,14 +591,14 @@ export class HiddenFileSync extends LiveSyncCommands { } else { const contentBin = await this.app.vault.adapter.readBinary(filename); const content = await arrayBufferToBase64(contentBin); - if (content == fileOnDB.data && !force) { + if (isDocContentSame(content, fileOnDB.data) && !force) { // Logger(`STORAGE <-- DB:${filename}: skipped (hidden) Not changed`, LOG_LEVEL_VERBOSE); return true; } await this.app.vault.adapter.writeBinary(filename, base64ToArrayBuffer(fileOnDB.data), { mtime: fileOnDB.mtime, ctime: fileOnDB.ctime }); try { //@ts-ignore internalAPI - await app.vault.adapter.reconcileInternalFile(filename); + await this.app.vault.adapter.reconcileInternalFile(filename); } catch (ex) { Logger("Failed to call internal API(reconcileInternalFile)", LOG_LEVEL_VERBOSE); Logger(ex, LOG_LEVEL_VERBOSE); @@ -653,7 +653,7 @@ export class HiddenFileSync extends LiveSyncCommands { await this.storeInternalFileToDatabase({ path: filename, ...stat }, true); try { //@ts-ignore internalAPI - await app.vault.adapter.reconcileInternalFile(filename); + await this.app.vault.adapter.reconcileInternalFile(filename); } catch (ex) { Logger("Failed to call internal API(reconcileInternalFile)", LOG_LEVEL_VERBOSE); Logger(ex, LOG_LEVEL_VERBOSE); @@ -691,7 +691,7 @@ export class HiddenFileSync extends LiveSyncCommands { const result: InternalFileInfo[] = []; for (const f of files) { const w = await f; - if (!await this.plugin.isIgnoredByIgnoreFiles(w.path)) { + if (await this.plugin.isIgnoredByIgnoreFiles(w.path)) { continue } result.push({ @@ -734,7 +734,7 @@ export class HiddenFileSync extends LiveSyncCommands { if (ignoreFilter && ignoreFilter.some(e => v.match(e))) { continue L1; } - if (!await this.plugin.isIgnoredByIgnoreFiles(v)) { + if (await this.plugin.isIgnoredByIgnoreFiles(v)) { continue L1; } files = files.concat(await this.getFiles(v, ignoreList, filter, ignoreFilter)); diff --git a/src/lib b/src/lib index 6efd115..8872807 160000 --- a/src/lib +++ b/src/lib @@ -1 +1 @@ -Subproject commit 6efd115e0e72cfdb775ae452a3ee1eb4798eed77 +Subproject commit 8872807f470cec6d6e7deb4a4ea76ad3664b4bfc diff --git a/src/main.ts b/src/main.ts index ddaabfb..52fc5f9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2569,9 +2569,14 @@ Or if you are sure know what had been happened, we can unlock the database from } } + /** + * Check the file is ignored by the ignore files. + * @param file + * @returns true if the file should be ignored, false if the file should be processed. + */ async isIgnoredByIgnoreFiles(file: string | TAbstractFile) { if (!this.settings.useIgnoreFiles) { - return true; + return false; } const filepath = file instanceof TFile ? file.path : file as string; if (this.ignoreFileCache.has(filepath)) { @@ -2579,14 +2584,14 @@ Or if you are sure know what had been happened, we can unlock the database from await this.readIgnoreFile(filepath); } if (!await isAcceptedAll(stripAllPrefixes(filepath as FilePathWithPrefix), this.ignoreFiles, (filename) => this.getIgnoreFile(filename))) { - return false; + return true; } - return true; + return false; } async isTargetFile(file: string | TAbstractFile) { const filepath = file instanceof TFile ? file.path : file as string; - if (this.settings.useIgnoreFiles && !await this.isIgnoredByIgnoreFiles(file)) { + if (this.settings.useIgnoreFiles && await this.isIgnoredByIgnoreFiles(file)) { return false; } return this.localDatabase.isTargetFile(filepath);