Skip to content

Commit 69841aa

Browse files
committed
Fix log file being synced if settings sync is enabled
1 parent 3458264 commit 69841aa

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/events-listener.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Vault, TAbstractFile, TFolder } from "obsidian";
22
import MetadataStore, { MANIFEST_FILE_NAME } from "./metadata-store";
33
import { GitHubSyncSettings } from "./settings/settings";
4-
import Logger from "./logger";
4+
import Logger, { LOG_FILE_NAME } from "./logger";
55
import GitHubSyncPlugin from "./main";
66

77
/**
@@ -145,6 +145,9 @@ export default class EventsListener {
145145
) {
146146
// Obsidian recommends not syncing the workspace files
147147
return false;
148+
} else if (filePath === `${this.vault.configDir}/${LOG_FILE_NAME}`) {
149+
// Don't sync the log file, doesn't make sense
150+
return false;
148151
} else if (
149152
this.settings.syncConfigDir &&
150153
filePath.startsWith(this.vault.configDir)

src/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Vault, normalizePath } from "obsidian";
22

3-
const LOG_FILE_NAME = "github-sync.log" as const;
3+
export const LOG_FILE_NAME = "github-sync.log" as const;
44

55
export default class Logger {
66
private logFile: string;

src/sync-manager.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import MetadataStore, {
1717
} from "./metadata-store";
1818
import EventsListener from "./events-listener";
1919
import { GitHubSyncSettings } from "./settings/settings";
20-
import Logger from "./logger";
20+
import Logger, { LOG_FILE_NAME } from "./logger";
2121
import { decodeBase64String, hasTextExtension } from "./utils";
2222
import GitHubSyncPlugin from "./main";
2323
import { BlobReader, Entry, Uint8ArrayWriter, ZipReader } from "@zip.js/zip.js";
@@ -233,6 +233,14 @@ export default class SyncManager {
233233
return;
234234
}
235235

236+
if (targetPath === `${this.vault.configDir}/${LOG_FILE_NAME}`) {
237+
// We don't want to download the log file if the user synced it in the past.
238+
// This is necessary because in the past we forgot to ignore the log file
239+
// from syncing if the user enabled configs sync.
240+
// To avoid downloading it we ignore it if still present in the remote repo.
241+
return;
242+
}
243+
236244
if (targetPath.split("/").last()?.startsWith(".")) {
237245
// We must skip hidden files as that creates issues with syncing.
238246
// This is fine as users can't edit hidden files in Obsidian anyway.
@@ -417,6 +425,16 @@ export default class SyncManager {
417425
throw new Error("Remote manifest is missing");
418426
}
419427

428+
if (
429+
Object.keys(files).contains(`${this.vault.configDir}/${LOG_FILE_NAME}`)
430+
) {
431+
// We don't want to download the log file if the user synced it in the past.
432+
// This is necessary because in the past we forgot to ignore the log file
433+
// from syncing if the user enabled configs sync.
434+
// To avoid downloading it we delete it if still around.
435+
delete files[`${this.vault.configDir}/${LOG_FILE_NAME}`];
436+
}
437+
420438
const blob = await this.client.getBlob({ sha: manifest.sha });
421439
const remoteMetadata: Metadata = JSON.parse(
422440
decodeBase64String(blob.content),

0 commit comments

Comments
 (0)