tannercollin/standardnotes-fs

Note is deleted immediately upon save when using customized Emacs

Ruin0x11 opened this issue · 9 comments

I tried mounting my notes, made a change to one in Emacs and quit. Later I listed the directory contents of the mountpoint and found that the note no longer existed there. I checked the copy on the website and found it was gone entirely. Since it was a weeks' work of work I panicked because I didn't have any other backups (my fault) and I watched as the local copy of the note got deleted on all my other devices as soon as I started the app on them. But then I learned that Standard Notes has a Trash feature, so I looked there and found that the note had just been marked "Deleted" instead, and I could restore it.

I tried creating a new note in the web app first and modifying it within the filesystem with Emacs and can reliably reproduce this. The note always becomes deleted from both the filesystem and the web app when saving it. I also noticed that Emacs was giving an Operation not permitted error when it tries to save, which I didn't see the first time, and by that time the note is deleted.

But this does not happen when using another editor, like Vim or nano. It seems like an edge case specific to something Emacs does, potentially with a customized config.

Still, do you think this is worth investigating, if it could cause data loss in the worst case? My Emacs configuration is at https://github.com/Ruin0x11/emacs.d.

Yes, this is definitely worth investigating. Thanks for reporting the issue.

I am completely unfamiliar with emacs, could you please run standardnotes-fs with the -vv flag (very verbose)? Then remove any sensitive information and upload the log to txt.t0.vc.

This will tell us exactly what emacs is doing.

Sure, here is the log: https://txt.t0.vc/VLTY

Here is what I did:

  1. Create a new note in the web app called "Test" and add some text to it.
  2. Mount snfs on the filesystem.
  3. Open the file "Test.txt" with Emacs, makes some changes, and try to save.
  4. Stop snfs with Ctrl-C.

For comparison I also made a log where I did the same thing with Vim instead: https://txt.t0.vc/YLNF

I do see it deleting the file:

DEBUG   : -> access /Test.txt (0,)
DEBUG   : -> access / (0,)
DEBUG   : -> access /Test.txt (2,)
DEBUG   : -> getxattr /Test.txt ('system.posix_acl_access',)
DEBUG   : -> access / (2,)
DEBUG   : -> getattr /
DEBUG   : -> open /Test.txt (32768,)
DEBUG   : -> read /Test.txt (4096, 0, 0)
DEBUG   : -> getxattr /Test.txt ('system.posix_acl_access',)
DEBUG   : -> flush /Test.txt (0,)
DEBUG   : -> release /Test.txt (0,)
DEBUG   : -> getattr /
DEBUG   : -> unlink /Test.txt ()
DEBUG   : -> access / (2,)
DEBUG   : -> getattr /
DEBUG   : -> getattr /
DEBUG   : -> getattr /
DEBUG   : -> create /Test.txt (33188,)
DEBUG   : -> getattr /
DEBUG   : -> getattr /
DEBUG   : -> create /Test.txt (33152,)

I just have no idea why... I'll keep thinking on it.

Closing for now

@tannercollin, it is definitely those backup settings. Is there a workaround besides disabling those?

@tannercollin, these settings specifically broke it for me:
ryanpcmcquen/linuxTweaks@f7cbc9d

I forget what's happening here. Is emacs trying to create hidden files in the same folder as a backup / temp file? Could you point the temp file directory somewhere else?

I am not sure, but the default Emacs behavior works correctly.