Skip to content

Conversation

@esmodea
Copy link

@esmodea esmodea commented Sep 18, 2025

I put together this fix, it has to do with this Issue: #37

here is some context:
Description
When I change any file in the vault it syncs properly but then after it syncs if I don't change that file before next sync it undoes my sync. I've been trying to use this plugin for a small team of devs so we can utilize the Kanban plugin Obsidian has and I can confirm two different machines, one on MacOS and one on Windows 11, have this problem.

Steps to reproduce

  1. Sync a notes file
  2. Change the notes file
  3. Sync the notes file
  4. Sync the notes file again
  5. See unchanged notes file

Copied Logs

{"timestamp":"2025-09-17T18:14:21.205Z","level":"INFO","message":"Received modify event","additional_data":"StorySquad FE General.md"}
{"timestamp":"2025-09-17T18:14:21.212Z","level":"INFO","message":"Updated modified file","additional_data":"StorySquad FE General.md"}
{"timestamp":"2025-09-17T18:14:27.207Z","level":"INFO","message":"Starting sync"}
{"timestamp":"2025-09-17T18:14:27.503Z","level":"INFO","message":"Actions to sync","additional_data":[{"type":"upload","filePath":"StorySquad FE General.md"}]}
{"timestamp":"2025-09-17T18:14:28.767Z","level":"INFO","message":"Sync done"}
{"timestamp":"2025-09-17T18:14:30.189Z","level":"INFO","message":"Starting sync"}
{"timestamp":"2025-09-17T18:14:30.208Z","level":"INFO","message":"Actions to sync","additional_data":[{"type":"download","filePath":"StorySquad FE General.md"}]}
{"timestamp":"2025-09-17T18:14:30.377Z","level":"INFO","message":"Received modify event","additional_data":"StorySquad FE General.md"}
{"timestamp":"2025-09-17T18:14:30.379Z","level":"INFO","message":"Updated just downloaded modified file","additional_data":"StorySquad FE General.md"}
{"timestamp":"2025-09-17T18:14:31.489Z","level":"INFO","message":"Sync done"}
{"timestamp":"2025-09-17T18:14:33.921Z","level":"INFO","message":"Starting sync"}
{"timestamp":"2025-09-17T18:14:33.961Z","level":"INFO","message":"Nothing to sync"}

I looked into it and it seems that in the file src/sync-manager.ts there's an if-else statement on line 729 that only checks if the localSHA !== localFile.sha. I believe it would be more accurate to also check remoteFile.lastModified < localFile.lastModified, as well as adding an else-if to the latter block to ensure that localSHA == localFile.sha && remoteFile.lastModified > localFile.lastModified evaluates to true before downloading the file.

Original code

if (localSHA !== localFile.sha) {
  actions.push({ type: "upload", filePath: filePath });
  return;
} else {
  actions.push({ type: "download", filePath: filePath });
  return;
}

My (somewhat) tested & modified code

if (localSHA !== localFile.sha && remoteFile.lastModified < localFile.lastModified) {
  actions.push({ type: "upload", filePath: filePath });
  return;
} else if(localSHA == localFile.sha && remoteFile.lastModified > localFile.lastModified) {
  actions.push({ type: "download", filePath: filePath });
  return;
}

@esmodea
Copy link
Author

esmodea commented Sep 18, 2025

Not sure if I'm just running the wrong node version or if the type errors are related to new updates to node packages but I also fixed those, can revert those changes if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant