Skip to content

Make XDG_CACHE_HOME variable more controllable #11715

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -319,19 +319,20 @@ private static ResolvedCacheFolder findCacheRootDefault() {
case LINUX -> {
ResolvedCacheFolder userCacheDir = null;
String xdgCacheValue = System.getenv("XDG_CACHE_HOME");
if (xdgCacheValue != null) {
try {
Path xdgCacheDir = Path.of(xdgCacheValue);
// Do not fail when XDG_CACHE_HOME value is invalid. Fall back to
// $HOME/.cache.
if (xdgCacheDir.isAbsolute()) {
userCacheDir = new ResolvedCacheFolder(xdgCacheDir, "XDG_CACHE_HOME env variable", xdgCacheDir);
} else {
emitWarning("The value of the environment variable 'XDG_CACHE_HOME' is not an absolute path. Using the default cache folder '%s'.", userHome.resolve(".cache"));
}
} catch (InvalidPathException notPath) {
emitWarning("The value of the environment variable 'XDG_CACHE_HOME' is not a valid path. Using the default cache folder '%s'.", userHome.resolve(".cache"));
if (xdgCacheValue == null) {
xdgCacheValue = System.getProperty("xdg.cache.home");
}
try {
Path xdgCacheDir = Path.of(xdgCacheValue);
// Do not fail when XDG_CACHE_HOME value is invalid. Fall back to
// $HOME/.cache.
if (xdgCacheDir.isAbsolute()) {
userCacheDir = new ResolvedCacheFolder(xdgCacheDir, "XDG_CACHE_HOME env/property variable", xdgCacheDir);
} else {
emitWarning("The value of the environment/property variable 'XDG_CACHE_HOME' is not an absolute path. Using the default cache folder '%s'.", userHome.resolve(".cache"));
}
} catch (InvalidPathException notPath) {
emitWarning("The value of the environment/property variable 'XDG_CACHE_HOME' is not a valid path. Using the default cache folder '%s'.", userHome.resolve(".cache"));
}
if (userCacheDir == null) {
userCacheDir = new ResolvedCacheFolder(userHome.resolve(".cache"), "user home", userHome);
Expand Down