mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2025-12-13 09:45:56 +00:00
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.
This commit is contained in:
@@ -273,7 +273,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
if (!filename) continue;
|
if (!filename) continue;
|
||||||
if (ignorePatterns.some(e => filename.match(e)))
|
if (ignorePatterns.some(e => filename.match(e)))
|
||||||
continue;
|
continue;
|
||||||
if (!await this.plugin.isIgnoredByIgnoreFiles(filename)) {
|
if (await this.plugin.isIgnoredByIgnoreFiles(filename)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,7 +434,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async storeInternalFileToDatabase(file: InternalFileInfo, forceWrite = false) {
|
async storeInternalFileToDatabase(file: InternalFileInfo, forceWrite = false) {
|
||||||
if (!await this.plugin.isIgnoredByIgnoreFiles(file.path)) {
|
if (await this.plugin.isIgnoredByIgnoreFiles(file.path)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const id = await this.path2id(file.path, ICHeader);
|
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 id = await this.path2id(filename, ICHeader);
|
||||||
const prefixedFileName = addPrefix(filename, ICHeader);
|
const prefixedFileName = addPrefix(filename, ICHeader);
|
||||||
const mtime = new Date().getTime();
|
const mtime = new Date().getTime();
|
||||||
if (!await this.plugin.isIgnoredByIgnoreFiles(filename)) {
|
if (await this.plugin.isIgnoredByIgnoreFiles(filename)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await runWithLock("file-" + prefixedFileName, false, async () => {
|
await runWithLock("file-" + prefixedFileName, false, async () => {
|
||||||
@@ -544,7 +544,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
async extractInternalFileFromDatabase(filename: FilePath, force = false) {
|
async extractInternalFileFromDatabase(filename: FilePath, force = false) {
|
||||||
const isExists = await this.app.vault.adapter.exists(filename);
|
const isExists = await this.app.vault.adapter.exists(filename);
|
||||||
const prefixedFileName = addPrefix(filename, ICHeader);
|
const prefixedFileName = addPrefix(filename, ICHeader);
|
||||||
if (!await this.plugin.isIgnoredByIgnoreFiles(filename)) {
|
if (await this.plugin.isIgnoredByIgnoreFiles(filename)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return await runWithLock("file-" + prefixedFileName, false, async () => {
|
return await runWithLock("file-" + prefixedFileName, false, async () => {
|
||||||
@@ -568,7 +568,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
await this.app.vault.adapter.remove(filename);
|
await this.app.vault.adapter.remove(filename);
|
||||||
try {
|
try {
|
||||||
//@ts-ignore internalAPI
|
//@ts-ignore internalAPI
|
||||||
await app.vault.adapter.reconcileInternalFile(filename);
|
await this.app.vault.adapter.reconcileInternalFile(filename);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
Logger("Failed to call internal API(reconcileInternalFile)", LOG_LEVEL_VERBOSE);
|
Logger("Failed to call internal API(reconcileInternalFile)", LOG_LEVEL_VERBOSE);
|
||||||
Logger(ex, 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 });
|
await this.app.vault.adapter.writeBinary(filename, base64ToArrayBuffer(fileOnDB.data), { mtime: fileOnDB.mtime, ctime: fileOnDB.ctime });
|
||||||
try {
|
try {
|
||||||
//@ts-ignore internalAPI
|
//@ts-ignore internalAPI
|
||||||
await app.vault.adapter.reconcileInternalFile(filename);
|
await this.app.vault.adapter.reconcileInternalFile(filename);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
Logger("Failed to call internal API(reconcileInternalFile)", LOG_LEVEL_VERBOSE);
|
Logger("Failed to call internal API(reconcileInternalFile)", LOG_LEVEL_VERBOSE);
|
||||||
Logger(ex, LOG_LEVEL_VERBOSE);
|
Logger(ex, LOG_LEVEL_VERBOSE);
|
||||||
@@ -591,14 +591,14 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
} else {
|
} else {
|
||||||
const contentBin = await this.app.vault.adapter.readBinary(filename);
|
const contentBin = await this.app.vault.adapter.readBinary(filename);
|
||||||
const content = await arrayBufferToBase64(contentBin);
|
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);
|
// Logger(`STORAGE <-- DB:${filename}: skipped (hidden) Not changed`, LOG_LEVEL_VERBOSE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
await this.app.vault.adapter.writeBinary(filename, base64ToArrayBuffer(fileOnDB.data), { mtime: fileOnDB.mtime, ctime: fileOnDB.ctime });
|
await this.app.vault.adapter.writeBinary(filename, base64ToArrayBuffer(fileOnDB.data), { mtime: fileOnDB.mtime, ctime: fileOnDB.ctime });
|
||||||
try {
|
try {
|
||||||
//@ts-ignore internalAPI
|
//@ts-ignore internalAPI
|
||||||
await app.vault.adapter.reconcileInternalFile(filename);
|
await this.app.vault.adapter.reconcileInternalFile(filename);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
Logger("Failed to call internal API(reconcileInternalFile)", LOG_LEVEL_VERBOSE);
|
Logger("Failed to call internal API(reconcileInternalFile)", LOG_LEVEL_VERBOSE);
|
||||||
Logger(ex, LOG_LEVEL_VERBOSE);
|
Logger(ex, LOG_LEVEL_VERBOSE);
|
||||||
@@ -653,7 +653,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
await this.storeInternalFileToDatabase({ path: filename, ...stat }, true);
|
await this.storeInternalFileToDatabase({ path: filename, ...stat }, true);
|
||||||
try {
|
try {
|
||||||
//@ts-ignore internalAPI
|
//@ts-ignore internalAPI
|
||||||
await app.vault.adapter.reconcileInternalFile(filename);
|
await this.app.vault.adapter.reconcileInternalFile(filename);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
Logger("Failed to call internal API(reconcileInternalFile)", LOG_LEVEL_VERBOSE);
|
Logger("Failed to call internal API(reconcileInternalFile)", LOG_LEVEL_VERBOSE);
|
||||||
Logger(ex, LOG_LEVEL_VERBOSE);
|
Logger(ex, LOG_LEVEL_VERBOSE);
|
||||||
@@ -691,7 +691,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
const result: InternalFileInfo[] = [];
|
const result: InternalFileInfo[] = [];
|
||||||
for (const f of files) {
|
for (const f of files) {
|
||||||
const w = await f;
|
const w = await f;
|
||||||
if (!await this.plugin.isIgnoredByIgnoreFiles(w.path)) {
|
if (await this.plugin.isIgnoredByIgnoreFiles(w.path)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
result.push({
|
result.push({
|
||||||
@@ -734,7 +734,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
if (ignoreFilter && ignoreFilter.some(e => v.match(e))) {
|
if (ignoreFilter && ignoreFilter.some(e => v.match(e))) {
|
||||||
continue L1;
|
continue L1;
|
||||||
}
|
}
|
||||||
if (!await this.plugin.isIgnoredByIgnoreFiles(v)) {
|
if (await this.plugin.isIgnoredByIgnoreFiles(v)) {
|
||||||
continue L1;
|
continue L1;
|
||||||
}
|
}
|
||||||
files = files.concat(await this.getFiles(v, ignoreList, filter, ignoreFilter));
|
files = files.concat(await this.getFiles(v, ignoreList, filter, ignoreFilter));
|
||||||
|
|||||||
2
src/lib
2
src/lib
Submodule src/lib updated: 6efd115e0e...8872807f47
13
src/main.ts
13
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) {
|
async isIgnoredByIgnoreFiles(file: string | TAbstractFile) {
|
||||||
if (!this.settings.useIgnoreFiles) {
|
if (!this.settings.useIgnoreFiles) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
const filepath = file instanceof TFile ? file.path : file as string;
|
const filepath = file instanceof TFile ? file.path : file as string;
|
||||||
if (this.ignoreFileCache.has(filepath)) {
|
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);
|
await this.readIgnoreFile(filepath);
|
||||||
}
|
}
|
||||||
if (!await isAcceptedAll(stripAllPrefixes(filepath as FilePathWithPrefix), this.ignoreFiles, (filename) => this.getIgnoreFile(filename))) {
|
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) {
|
async isTargetFile(file: string | TAbstractFile) {
|
||||||
const filepath = file instanceof TFile ? file.path : file as string;
|
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 false;
|
||||||
}
|
}
|
||||||
return this.localDatabase.isTargetFile(filepath);
|
return this.localDatabase.isTargetFile(filepath);
|
||||||
|
|||||||
Reference in New Issue
Block a user