buffrs icon indicating copy to clipboard operation
buffrs copied to clipboard

Credentials storage does not respect the XDG specification

Open xfbs opened this issue 1 year ago • 2 comments

Currently, the credentials are stored in a hard-coded path determined by the $BUFFRS_HOME variable, or in ~/.buffrs/credentials.toml, see this code. While this is initially a sensible approach, there are some improvements that could be made.

Issues

Depending on the operating system that you are using, you may not want to store things in your home directory. Some operating systems do not understand the concept of dotfiles (files or folders, which are hidden by default due to a leading dot in their name). Some people may prefer to not clobber their home directories with configuration, but rather store it somewhere else.

In general, it is warmly recommended to adhere to a standard when it comes to storing configuration rather than "clobbering" user's home directories with it. See also

Standard

For this reason, the XDG group has a specification called the XDG Base Directory Specification which sets standards that applications should respect. One of these standards defines where configuration should be stored. The default location as per this standard would be ~/.config/buffrs/credentials.toml, but the spec also defines environment variables that can be set to change this.

Similarly, Windows has the KNOWNFOLDERID API and macOS the Standard Directories.

Solution

We can use the dirs crate to consume these standards. Another crate offered by the same team is directories, which should make it even easier for us.

Notes

Note that many applications still do not respect the XDG standard, including my beloved editor vim. It is not the end of the world if we do not adhere to them. But I do believe that it is a good standard and that there are few reasons not to stick to it. Ideally, we can stick to it in a backwards-compatible way, such that the application would prefer configuration created in the XDG-compatible paths, but would also search the current locations.

See Also

xfbs avatar Oct 10 '23 09:10 xfbs

Sounds sensible to me!

mara-schulke avatar Oct 10 '23 13:10 mara-schulke

We can use the dirs crate to consume these standards. Another crate offered by the same team is directories, which should make it even easier for us.

Both crates are not very nice to use for macOS users: https://github.com/dirs-dev/directories-rs/issues/47

buffrs is a binary tool so we probably want it to respect the XDG spec even on macOS (at least for the config, the cache can be wherever, as users we don't have to interact with it)

poliorcetics avatar Apr 05 '24 12:04 poliorcetics