Slackadays/Clipboard

global_path.persistent should handle case where XDG_STATE_HOME is not defined

bbhtt opened this issue · 1 comments

bbhtt commented

Describe the bug

Run cb copy and cb paste on linux where none of the XDG_* directory variable is set by default.

It creates a $HOME/.clipboard directory.

Instead it should fallback to ~/.local/state when XDG_STATE_HOME that is how XDG basedir variables are typically handled in programs because nothing exports these variables in the environment by default.

You can see the spec that mentions it https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html

$XDG_STATE_HOME defines the base directory relative to which user-specific state files should be stored. If $XDG_STATE_HOME is either not set or empty, a default equal to $HOME/.local/state should be used.

global_path.persistent =
(getenv("CLIPBOARD_PERSISTDIR") ? getenv("CLIPBOARD_PERSISTDIR") : (getenv("XDG_STATE_HOME") ? getenv("XDG_STATE_HOME") : global_path.home)) / constants.persistent_directory_name;

To Reproduce

See above

Expected behavior

.clipboard should be in ~/.local/state/.clipboard

Screenshots

N/A

Version

0.8.3

Questionnaire
Check these boxes to see if your issue is valid or not.

  • If I compiled CB, then any errors that may be present don't mention "LTO error" (this is sadly a bug with the compiler, not Clipboard)
  • If I compiled CB, then any errors that may be present don't mention "XYZ has not been defined in namespace std" (this sadly means you need a compiler with C++20 support, so upgrade first)
  • I check all these boxes without reading them
  • I think bachata is the best music
  • I'm using the latest commit/release (we only support the latest)
  • If I downloaded CB from GitHub Actions or with the install script, any errors that may be present don't mention "GLIBC XYZ not found" (your system is sadly too outdated for CB, so upgrade it)

Additional context

n/A

bbhtt commented

This does not affect flatpak/snap because inside the sandbox XDG_* variables are defined to support custom locations eg. ~/.var/app/<app-id>/ etc.