From 51b9cb85bc18310c1fc51b82449a8854dcf53cd5 Mon Sep 17 00:00:00 2001 From: BWindey <93756910+BWindey@users.noreply.github.com> Date: Tue, 29 Jul 2025 19:11:56 +0200 Subject: [PATCH] Fix get_config_dir() implementation (#2348) * Fix get_config_dir() implementation * Formatting and fallback to home if the path is empty. --------- Co-authored-by: Christoffer Lerno --- lib/std/os/env.c3 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/std/os/env.c3 b/lib/std/os/env.c3 index e2875a4b9..c7aaff711 100644 --- a/lib/std/os/env.c3 +++ b/lib/std/os/env.c3 @@ -79,7 +79,7 @@ fn String? get_home_dir(Allocator allocator) <* -Returns the current user's config directory. + Returns the current user's config directory. *> fn Path? get_config_dir(Allocator allocator) => @pool() { @@ -87,13 +87,15 @@ fn Path? get_config_dir(Allocator allocator) => @pool() return path::new(allocator, tget_var("AppData")); $else $if env::DARWIN: - String s = tget_var("HOME")!; + String home_dir = tget_var("HOME")!; const DIR = "Library/Application Support"; $else - String s = tget_var("XDG_CONFIG_HOME") ?? tget_var("HOME")!; + String? config_path = tget_var("XDG_CONFIG_HOME"); + if (try config_path && config_path.len > 0) return path::new(allocator, config_path); + String home_dir = tget_var("HOME")!; const DIR = ".config"; $endif - return path::temp(s).append(allocator, DIR); + return path::temp(home_dir).append(allocator, DIR); $endif }