Skip to content

Commit

Permalink
os: directory functions should prefer cached home if available
Browse files Browse the repository at this point in the history
This fixes tests as well if env vars are set.
  • Loading branch information
mitchellh committed Jan 3, 2025
1 parent 7eb35d7 commit e03c428
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/os/xdg.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ fn dir(
opts: Options,
internal_opts: InternalOptions,
) ![]u8 {
// If we have a cached home dir, use that.
if (opts.home) |home| {
return try std.fs.path.join(alloc, &[_][]const u8{
home,
internal_opts.default_subdir,
opts.subdir orelse "",
});
}

// First check the env var. On Windows we have to allocate so this tracks
// both whether we have the env var and whether we own it.
// on Windows we treat `LOCALAPPDATA` as a fallback for `XDG_CONFIG_HOME`
Expand Down Expand Up @@ -93,15 +102,6 @@ fn dir(
return try alloc.dupe(u8, env);
}

// If we have a cached home dir, use that.
if (opts.home) |home| {
return try std.fs.path.join(alloc, &[_][]const u8{
home,
internal_opts.default_subdir,
opts.subdir orelse "",
});
}

// Get our home dir
var buf: [1024]u8 = undefined;
if (try homedir.home(&buf)) |home| {
Expand Down

0 comments on commit e03c428

Please sign in to comment.