diff --git a/src/events-listener.ts b/src/events-listener.ts index de305be..15093c4 100644 --- a/src/events-listener.ts +++ b/src/events-listener.ts @@ -1,7 +1,7 @@ import { Vault, TAbstractFile, TFolder } from "obsidian"; import MetadataStore, { MANIFEST_FILE_NAME } from "./metadata-store"; import { GitHubSyncSettings } from "./settings/settings"; -import Logger from "./logger"; +import Logger, { LOG_FILE_NAME } from "./logger"; import GitHubSyncPlugin from "./main"; /** @@ -145,6 +145,9 @@ export default class EventsListener { ) { // Obsidian recommends not syncing the workspace files return false; + } else if (filePath === `${this.vault.configDir}/${LOG_FILE_NAME}`) { + // Don't sync the log file, doesn't make sense + return false; } else if ( this.settings.syncConfigDir && filePath.startsWith(this.vault.configDir) diff --git a/src/logger.ts b/src/logger.ts index 36077e1..4273fef 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,6 +1,6 @@ import { Vault, normalizePath } from "obsidian"; -const LOG_FILE_NAME = "github-sync.log" as const; +export const LOG_FILE_NAME = "github-sync.log" as const; export default class Logger { private logFile: string; diff --git a/src/sync-manager.ts b/src/sync-manager.ts index d0f6f92..9296dca 100644 --- a/src/sync-manager.ts +++ b/src/sync-manager.ts @@ -17,7 +17,7 @@ import MetadataStore, { } from "./metadata-store"; import EventsListener from "./events-listener"; import { GitHubSyncSettings } from "./settings/settings"; -import Logger from "./logger"; +import Logger, { LOG_FILE_NAME } from "./logger"; import { decodeBase64String, hasTextExtension } from "./utils"; import GitHubSyncPlugin from "./main"; import { BlobReader, Entry, Uint8ArrayWriter, ZipReader } from "@zip.js/zip.js"; @@ -233,6 +233,14 @@ export default class SyncManager { return; } + if (targetPath === `${this.vault.configDir}/${LOG_FILE_NAME}`) { + // We don't want to download the log file if the user synced it in the past. + // This is necessary because in the past we forgot to ignore the log file + // from syncing if the user enabled configs sync. + // To avoid downloading it we ignore it if still present in the remote repo. + return; + } + if (targetPath.split("/").last()?.startsWith(".")) { // We must skip hidden files as that creates issues with syncing. // This is fine as users can't edit hidden files in Obsidian anyway. @@ -417,6 +425,16 @@ export default class SyncManager { throw new Error("Remote manifest is missing"); } + if ( + Object.keys(files).contains(`${this.vault.configDir}/${LOG_FILE_NAME}`) + ) { + // We don't want to download the log file if the user synced it in the past. + // This is necessary because in the past we forgot to ignore the log file + // from syncing if the user enabled configs sync. + // To avoid downloading it we delete it if still around. + delete files[`${this.vault.configDir}/${LOG_FILE_NAME}`]; + } + const blob = await this.client.getBlob({ sha: manifest.sha }); const remoteMetadata: Metadata = JSON.parse( decodeBase64String(blob.content),