From cb3a51e47f5cac164a0c73c60c524e6f6b7e4bac Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Mon, 5 Jan 2026 10:56:14 -0800 Subject: [PATCH] now that we have a cache directory, default geocache file to that directory --- src/config.zig | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/config.zig b/src/config.zig index 7b2a4ab..197a7ca 100644 --- a/src/config.zig +++ b/src/config.zig @@ -17,10 +17,10 @@ pub const Config = struct { // Get XDG_CACHE_HOME or default to ~/.cache const home = env.get("HOME") orelse "/tmp"; const xdg_cache = env.get("XDG_CACHE_HOME") orelse - try std.fmt.allocPrint(allocator, "{s}/.cache", .{home}); + try std.fs.path.join(allocator, &[_][]const u8{ home, ".cache" }); defer if (env.get("XDG_CACHE_HOME") == null) allocator.free(xdg_cache); - const default_cache_dir = try std.fmt.allocPrint(allocator, "{s}/wttr", .{xdg_cache}); + const default_cache_dir = try std.fs.path.join(allocator, &[_][]const u8{ xdg_cache, "wttr" }); defer allocator.free(default_cache_dir); return Config{ @@ -42,7 +42,7 @@ pub const Config = struct { env.get("WTTR_CACHE_DIR") orelse default_cache_dir, }); }, - .geocache_file = if (env.get("WTTR_GEOCACHE_FILE")) |v| try allocator.dupe(u8, v) else null, + .geocache_file = if (env.get("WTTR_GEOCACHE_FILE")) |v| try allocator.dupe(u8, v) else try std.fs.path.join(allocator, &[_][]const u8{ default_cache_dir, "geocache.json" }), .ip2location_api_key = if (env.get("IP2LOCATION_API_KEY")) |v| try allocator.dupe(u8, v) else null, .ip2location_cache_file = blk: { if (env.get("IP2LOCATION_CACHE_FILE")) |v| { @@ -71,5 +71,4 @@ test "config loads defaults" { try std.testing.expectEqualStrings("0.0.0.0", cfg.listen_host); try std.testing.expectEqual(@as(u16, 8002), cfg.listen_port); try std.testing.expectEqual(@as(usize, 10_000), cfg.cache_size); - try std.testing.expect(cfg.geocache_file == null); }