Fix log file being synced if settings sync is enabled

This commit is contained in:
Silvano Cerza 2025-04-20 21:25:24 +02:00
parent 345826443f
commit 69841aa574
3 changed files with 24 additions and 3 deletions

View file

@ -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)

View file

@ -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;

View file

@ -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),