Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's the difference between state_dir and data_local_dir? #70

Open
rosefromthedead opened this issue Jan 3, 2022 · 5 comments
Open

Comments

@rosefromthedead
Copy link

rosefromthedead commented Jan 3, 2022

On Windows, data_local_dir is LocalAppData which AIUI is like RoamingAppData but not synchronised across machines. The docs for state_dir say that it's not synchronised across machines. Are they not the same thing? If they are, could data_local_dir's behaviour on Linux be changed to match state_dir? Currently state_dir is only useful on Linux, and to me it would make sense to merge it into the existing data_local_dir function.

@zapashcanon
Copy link

In ocamlpro/directories I made the choice to have state_dir being the same as cache_dir in macOS and Windows because I believe it's the closest thing to it.

@soc
Copy link
Collaborator

soc commented Jan 9, 2022

The state dir has some very specific requirements and guarantees compared to the cache dir.

My reasoning was that filling in cache dir for state dir on Windows/macOS feels wrong:

  • Either you need need state dir's additional behaviors – then pretending Win/macOS offers them is bad;
  • or you don't need them – then simply use the cache dir.

(All the above applies the same if you replace "cache dir" with "data local dir".)

@zapashcanon
Copy link

I don't believe these additional behaviors are "needed" and there's also no guarantees:

The $XDG_STATE_HOME contains state data that should persist between (application) restarts

It says should and not must. They're just some nice things to have when possible. Thus:

  • either you want them if available (but it wouldn't be an issue if they're not) – then pretending Win/macOS offers thems is OK ;
  • either you don't want them – then simply use the cache dir.

A basic use case is an interpreter (e.g. python, or utop in my case) where you would like to keep an history of the commands entered by the user. Clearly the history file fits better in state dir, but it doesn't hurt to put them in cache dir when state dir is not available.

@soc
Copy link
Collaborator

soc commented Jan 10, 2022

I don't believe these additional behaviors are "needed" and there's also no guarantees:

Ah sorry, I had state dir switched with runtime dir in my head. That makes my argument weaker in that regard, as the runtime dir has higher requirements.

A basic use case is an interpreter (e.g. python, or utop in my case) where you would like to keep an history of the commands entered by the user. Clearly the history file fits better in state dir, but it doesn't hurt to put them in cache dir when state dir is not available.

I think this would be fine for this use-case, but I'm not sure it applies to every use-case of the state dir though.
In the end, the library isn't meant to make (and can't make) such determinations that work for everyone.

In your case, writing code that picks the state dir on Linux and the cache dir on Windows/macOS would be a perfectly valid solution.

@zapashcanon
Copy link

Ah sorry, I had state dir switched with runtime dir in my head. That makes my argument weaker in that regard, as the runtime dir has higher requirements.

Indeed, they're different. 😄

Let's say you have to use state dir. On Linux, fine. Then you're on macOS or Windows and it's not available, which directory are you going to use ? Not data dir (users don't want to backup states...), you're left with cache dir. Then, I prefer the library to pick it for me automatically instead of having to write code to choose cache dir when state dir is not available.

But if you find a use case where this is not true, I'll be interested ! :)

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

No branches or pull requests

3 participants