Skip to content

Support XDG Base directory specification for Linux - #264

Open
WhiredPlanck wants to merge 2 commits into
TypesettingTools:masterfrom
WhiredPlanck:xdg-base
Open

Support XDG Base directory specification for Linux#264
WhiredPlanck wants to merge 2 commits into
TypesettingTools:masterfrom
WhiredPlanck:xdg-base

Conversation

@WhiredPlanck

@WhiredPlanck WhiredPlanck commented Jan 3, 2025

Copy link
Copy Markdown

This PR will fix Issue Aegisub#226. Adapted from aria2/aria2@8bc1d37.

The basic idea just is:

  • If $HOME/.aegisub exists, then the program will still read/write config/cache/data/state from there;
  • If $HOME/.aegisub doesn't exist, then the program will read/write config/cache/data/state from corresponding XDG base Directory.

The original PR is here: wangqr#132

@witchymary

witchymary commented Jan 4, 2025

Copy link
Copy Markdown
Contributor

I'm pretty sure this will still run into the issues I fixed here: arch1t3cht@b5a071b

Also worth noting that this will break regardless due to this line in Dependency Control (https://github.com/TypesettingTools/DependencyControl/blob/9b8d615f18e295f4777ea606a7173465bdaf140d/modules/DependencyControl/Record.moon#L44). It needs to be changed in there as well

Comment thread libaegisub/unix/path.cpp Outdated
@WhiredPlanck

Copy link
Copy Markdown
Author

I'm pretty sure this will still run into the issues I fixed here: arch1t3cht@b5a071b

Also worth noting that this will break regardless due to this line in Dependency Control (https://github.com/TypesettingTools/DependencyControl/blob/9b8d615f18e295f4777ea606a7173465bdaf140d/modules/DependencyControl/Record.moon#L44). It needs to be changed in there as well

You're right, I will fix it.

Comment thread libaegisub/unix/path.cpp
throw agi::EnvironmentError("Could not get home directory. Make sure HOME is set.");
}

std::string xdg_dir(std::string_view token, agi::fs::path const& fallback) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

token is not the right name for the parameter... (env_name would be better)

Comment thread libaegisub/unix/path.cpp
SetToken("?state", old_root);
} else {
SetToken("?user", xdg_config/"aegisub");
SetToken("?local", xdg_cache/"aegisub");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Calling a cache dir ?local is somewhat misleading, but I guess we have to keep it for compatibility. ?cache would be a better name though.

Comment thread libaegisub/unix/path.cpp

std::string xdg_dir(std::string_view token, agi::fs::path const& fallback) {
const char *env = getenv(token.data());
if (env) return env;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The environment variable must be ignored if it is empty or doesn't contain an absolute path

@filip-hejsek

Copy link
Copy Markdown
Contributor

This PR causes a crash on startup when the XDG dirs don't exist. This part of the spec is relevent:

If, when attempting to write a file, the destination directory is non-existent an attempt should be made to create it with permission 0700

@line0

line0 commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Also worth noting that this will break regardless due to this line in Dependency Control (https://github.com/TypesettingTools/DependencyControl/blob/9b8d615f18e295f4777ea606a7173465bdaf140d/modules/DependencyControl/Record.moon#L44). It needs to be changed in there as well

Support added in TypesettingTools/DependencyControl#36.

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.

5 participants