neverest icon indicating copy to clipboard operation
neverest copied to clipboard

Consider moving state to `$XDG_STATE_HOME` as opposed to `$XDG_CACHE_HOME`

Open shymega opened this issue 1 year ago • 8 comments

To follow-up from our Matrix chat:

Currently, neverest stores state/locks in two places: $XDG_CACHE_HOME/pimalaya and $XDG_RUNTIME_DIR/pimalaya.

The former is the one I'd like to see changed to $XDG_STATE_HOME/pimalaya, as storing in $XDG_CACHE_HOME/pimalaya runs the risk of accidental deletion of the state files.

The latter isn't as much of an issue.

We could, maybe in the future, store state in the IMAP/Maildir backends as well.

shymega avatar Sep 11 '24 23:09 shymega

In how far is it safe vs. not safe to delete $XDG_CACHE_HOME/pimalaya? Could anything go wrong next time I run neverest synchronize? If yes, that folder should definitely be considered state.

codethief avatar Sep 20 '24 06:09 codethief

In how far is it safe vs. not safe to delete $XDG_CACHE_HOME/pimalaya? Could anything go wrong next time I run neverest synchronize? If yes, that folder should definitely be considered state.

The scariest scenario is when you delete your data, the root-dir, without deleting the cache. It may consider that all emails were removed and needs to be removed remotely.

If you delete the cache, Neverest will not be able to know if sth has been deleted right side or added left side. For now it comes with safe defaults: it will always take the path that does not delete data. Worst case you just get back emails you previously deleted, or get duplicates (same email in trash and inbox).

I believe cache is not crucial. It just helps the sync to take the right decision. Hence my initial choice behind the cache directory. That said, the state directory also makes sense, and may be a safer default. So let's do it!

soywod avatar Sep 20 '24 06:09 soywod

@soywod Thanks for elaborating! That is quite scary indeed.

Would it make sense to add a "readonly" flag to protect either left or right side from accidental changes or a flag to indicate the "direction" of the sync? In my case I'm only ever interested in syncing from left to right. (Except for the hopefully unlikely case when I need to restore left from my backup on the right.)

codethief avatar Sep 20 '24 17:09 codethief

Would it make sense to add a "readonly" flag to protect either left or right side from accidental changes or a flag to indicate the "direction" of the sync?

You have permissions for that purpose: https://github.com/pimalaya/neverest/blob/92fa58db23cd6933c50e70f08318b042e87e1828/config.sample.toml#L82-L91

soywod avatar Sep 20 '24 18:09 soywod

In how far is it safe vs. not safe to delete $XDG_CACHE_HOME/pimalaya? Could anything go wrong next time I run neverest synchronize? If yes, that folder should definitely be considered state.

It's not safe to delete it IMO, given it stores state. It should be in the XDG state directory - cache is for temporary files, and admittedly - sometimes state - but for this use-case of neverest, this should not be considered safe.

shymega avatar Dec 24 '24 19:12 shymega

Then I will fix it for the next release. Thank you for your feedback!

soywod avatar Dec 25 '24 17:12 soywod

Did you mean to add the Invalid label? 🤔

shymega avatar Dec 25 '24 17:12 shymega

Yes, in a way that "this implementation does not seem right". But not sure if it's a common practice, I can just remove it.

soywod avatar Dec 25 '24 17:12 soywod