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

Clean up $XDG_DATA_DIRS and adhere to the XDG Base Directory Specification #150

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

antecrescent
Copy link

@antecrescent antecrescent commented Apr 29, 2024

The first commit fixes a startup error (#115), when $XDG_DATA_DIRS is not defined and thus gets incorrectly set
to
:/run/host/usr/share:/var/lib/snapd/desktop:/var/lib/flatpak/exports/share:${HOME}/.local/share/flatpak/exports/share while the XDG Base Directory Specification states:

If $XDG_DATA_DIRS is either not set or empty, a value equal to /usr/local/share/:/usr/share/ should be used.

The second commit removes entries from $XDG_DATA_DIRS that Snapd and Flatpak set themselves already.

I found a downstream incident report, where Junction "doesn't work with programs that do their own weird stuff and end up clearing the env". I didn't investigate this further, since I believe that this was either a user error or the programs in question need to properly handle $XDG* variables.
I mentioned it in case it's relevant to this PR.

The XDG Base Directory Specification states:
> If $XDG_DATA_DIRS is either not set or empty, a value equal to
> /usr/local/share/:/usr/share/ should be used.

Fix: sonnyp#115
@@ -1,4 +1,4 @@
#!/usr/bin/env -S XDG_DATA_DIRS=${XDG_DATA_DIRS}:/run/host/usr/share:/var/lib/snapd/desktop:/var/lib/flatpak/exports/share:${HOME}/.local/share/flatpak/exports/share gjs -m
#!/usr/bin/env -S XDG_DATA_DIRS=${XDG_DATA_DIRS:-/usr/local/share:/usr/share}:/run/host/usr/share gjs -m
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with this syntax - can you explain the - or point me to documentation

Copy link
Author

@antecrescent antecrescent Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick response! If you are referring to the ${var:-default} shell syntax, it substitutes the default value default if ${var} is unset or null:

From the Bash manpage:

${parameter:-word}
Use Default Values. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonnyp Can I help you with anything else? :)

Copy link

@nachum37 nachum37 Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick response! If you are referring to the ${var:-default} shell syntax, it substitutes the default value default if ${var} is unset or null:

From the Bash manpage:

${parameter:-word}
Use Default Values. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.

@antecrescent

Something doesn't work with this syntax, the following error is received:

$ re.sonny.Junction
/usr/bin/env: only ${VARNAME} expansion is supported, error at: ${XDG_DATA_DIRS:-/usr/local/share:/usr/share}:/run/host/usr/share gjs -m

Maybe env (at least on my arch) does not support this ${parameter:-word} shell syntax.

This syntax works (of course it will overwrite the value)

#!/usr/bin/env -S XDG_DATA_DIRS=/usr/local/share:/usr/share:/run/host/usr/share gjs -m

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

Successfully merging this pull request may close these issues.

3 participants