diff options
| author | Ian Johnson <ian@ianjohnson.dev> | 2024-08-19 23:11:32 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-08-19 23:30:14 -0700 |
| commit | 0a70455095a19a4c18497e6786ca6139c1cc2892 (patch) | |
| tree | e3b5ca0499e459ac413a2e4152dcae5ad6a9b833 /src | |
| parent | dffc8c44f9a01aa05ea364ffdc71509d15bc2601 (diff) | |
| download | zig-0a70455095a19a4c18497e6786ca6139c1cc2892.tar.gz zig-0a70455095a19a4c18497e6786ca6139c1cc2892.zip | |
Fix handling of empty XDG environment variables
Closes #21132
According to the XDG Base Directory specification
(https://specifications.freedesktop.org/basedir-spec/latest/#variables),
empty values for these environment variables should be treated the same
as if they are unset. Specifically, for the instances changed in this
commit,
> $XDG_DATA_HOME defines the base directory relative to which
> user-specific data files should be stored. If $XDG_DATA_HOME is either
> not set **or empty**, a default equal to $HOME/.local/share should be
> used.
and
> $XDG_CACHE_HOME defines the base directory relative to which
> user-specific non-essential data files should be stored. If
> $XDG_CACHE_HOME is either not set **or empty**, a default equal to
> $HOME/.cache should be used.
(emphasis mine)
In addition to the case mentioned in the linked issue, all other uses of
XDG environment variables were corrected.
Diffstat (limited to 'src')
| -rw-r--r-- | src/introspect.zig | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/introspect.zig b/src/introspect.zig index 341b1cddeb..4193440461 100644 --- a/src/introspect.zig +++ b/src/introspect.zig @@ -90,8 +90,11 @@ pub fn resolveGlobalCacheDir(allocator: mem.Allocator) ![]u8 { if (builtin.os.tag != .windows) { if (std.zig.EnvVar.XDG_CACHE_HOME.getPosix()) |cache_root| { - return fs.path.join(allocator, &[_][]const u8{ cache_root, appname }); - } else if (std.zig.EnvVar.HOME.getPosix()) |home| { + if (cache_root.len > 0) { + return fs.path.join(allocator, &[_][]const u8{ cache_root, appname }); + } + } + if (std.zig.EnvVar.HOME.getPosix()) |home| { return fs.path.join(allocator, &[_][]const u8{ home, ".cache", appname }); } } |
