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

Wrong way to look up Documents dir on Linux #553

Closed
jn64 opened this issue Jul 17, 2023 · 7 comments
Closed

Wrong way to look up Documents dir on Linux #553

jn64 opened this issue Jul 17, 2023 · 7 comments

Comments

@jn64
Copy link
Contributor

jn64 commented Jul 17, 2023

It seems like Cardinal is looking for the env var XDG_DOCUMENTS_DIR:

if (const char* const xdgEnv = getenv("XDG_DOCUMENTS_DIR"))
asset::userDir = system::join(xdgEnv, "Cardinal");
else
asset::userDir = system::join(homeDir(), "Documents", "Cardinal");

XDG_DOCUMENTS_DIR is not a known env var in the XDG basedir spec (unlike say XDG_CONFIG_HOME)

I think this was mistakenly taken from user-dirs.dirs(5). XDG_DOCUMENTS_DIR is a variable only used inside the user-dirs.dirs file, not an env var. This file is meant to be sourced by shell scripts. I know of some programs (e.g. JUCE) parse this file to get the various user folders.

The result is that Cardinal is looking in ~/Documents, even though my documents folder is ~/docs:

# ~/.config/user-dirs.dirs
XDG_DESKTOP_DIR="$HOME"
XDG_DOCUMENTS_DIR="$HOME/docs"
XDG_DOWNLOAD_DIR="$HOME/downloads"
XDG_MUSIC_DIR="$HOME/music"
XDG_PICTURES_DIR="$HOME/pics"
XDG_PUBLICSHARE_DIR="$HOME/public"
XDG_TEMPLATES_DIR="$HOME/templates"
XDG_VIDEOS_DIR="$HOME/vids"
@falkTX
Copy link
Contributor

falkTX commented Jul 17, 2023

well that makes it kinda useless.

for storing documents the "config" dir is wrong, we dont want hidden configuration files here.
the fallback is basically the same as VCV Rack btw

@falkTX
Copy link
Contributor

falkTX commented Jul 17, 2023

so if I understood this right we need to basically:

  1. check if XDG_CONFIG_HOME is set, fallback to $HOME/.config if not
  2. read $_CONFIG_DIR/user-dirs.dirs and try to parse it without errors
  3. use a XDG_DOCUMENTS_DIR inside it if available, otherwise fallback to $HOME/Documents (or maybe use localization to find fallback docs path, but that becomes too much)

@jn64
Copy link
Contributor Author

jn64 commented Jul 17, 2023

That sounds correct. I found more info here: https://freedesktop.org/wiki/Software/xdg-user-dirs/

For application code the hope is that the various desktops will integrate this and have a nice API to find these directories.

I don't know if there are such APIs or if they'll be useful to you. It seems like other projects implement it themselves, although on a closer look, JUCE assumes ~/.config, which I guess is wrong. wxWidgets seems to have a correct implementation.

(I think the whole thing is stupid, but as a user I can either use the stupid thing to get what I want, or not get what I want...)

@falkTX
Copy link
Contributor

falkTX commented Jul 17, 2023

both of those implementations don't bother to check for # that would make something a comment, or duplicated env vars where the last one is what should end up being used, or prefixes added to the var like PLEASE_IGNORE_XDG_DOCUMENTS_DIR=/not/this/one.

both seem to use an awful way for parsing, no error checking done at all besides checking if the folder exists...

that at least makes it easier on our side, as the bar is quite low for a quick and dirty implementation

@jn64
Copy link
Contributor Author

jn64 commented Jul 17, 2023

Quick and dirty will do IMO. If the user has a malformed file, other things will break before they get to Cardinal.

@EnigmaCurry
Copy link
Contributor

I think you can just exec xdg-user-dir DOCUMENTS to get the correct directory path

@falkTX
Copy link
Contributor

falkTX commented Sep 3, 2023

yes, but exec within a plugin is frowned upon as it duplicates file descriptors and other things.
anyway the parsing of the file is not that complex

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