From e03c428728c1bb224c1114caa4207f05aa82ff19 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 3 Jan 2025 09:46:13 -0800 Subject: [PATCH] os: directory functions should prefer cached home if available This fixes tests as well if env vars are set. --- src/os/xdg.zig | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/os/xdg.zig b/src/os/xdg.zig index a5b29abe4..1383679fe 100644 --- a/src/os/xdg.zig +++ b/src/os/xdg.zig @@ -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` @@ -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| {