dendronhq / dendron

The personal knowledge management (PKM) tool that grows as you do!
https://wiki.dendron.so
Apache License 2.0
6.63k stars 252 forks source link

cmd+shift+i sometimes overwrites existing journal #2368

Open chmac opened 2 years ago

chmac commented 2 years ago

Please select the area your bug applies to. (Multiple selections are Possible. You can leave blank if you're not sure.)

Describe the bug

If I git pull a vault, and then immediately switch to dendron and hit cmd+shift+i, the journal note that was just pulled is sometimes overwritten.

To Reproduce

Steps to reproduce the behavior:

  1. Create a vault, add a journal template
  2. On a second machine, add a journal note for today, make some edits, then git push
  3. Back on the first machine, open dendron, press cmd+shift+i, note the blank journal page
  4. Close the journal note
  5. Switch to terminal and run git clean -f && git pull
  6. Switch back to Dendron and cmd+shift+i again
  7. Note that your journal note is now blank again and git status shows the note changed

Expected behavior

Dendron should never overwrite a file on disk with an empty template, even if that file has not arrived in the dendron index, or otherwise.

Additional context

I think this requires pretty quick switching back and forth between the terminal and dendron. I've now seen it happen on several occasions. But always with the same flow, I open the journal, realise I started today's journal on another machine, switch back, git pull, and then my journal gets wiped.

Harshita-mindfire commented 2 years ago

Thanks for reporting the bug. We will look into this and update you when it is done 🙏

jonathanyeung commented 2 years ago

@hikchoi (or whoever looks at this one)- this is likely due to a race condition with the file watcher not propagating file changes from git pull to the engine in time (or perhaps the updates never made it at all).

On quick inspection - we should probably strengthen the check if the note already exists check here to also do an fs-extra file system check: https://github.com/dendronhq/dendron/blob/86482b74d2916658fab4bf8e3e3897436edbade6/packages/engine-server/src/drivers/file/storev2.ts#L1063