mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Use $HOME/Library/Caches
on macOS instead of $HOME/.cache
This commit is contained in:
@ -30,6 +30,22 @@ pub fn config(alloc: Allocator, opts: Options) ![]u8 {
|
||||
|
||||
/// Get the XDG cache directory. The returned value is allocated.
|
||||
pub fn cache(alloc: Allocator, opts: Options) ![]u8 {
|
||||
// On macOS we should use ~/Library/Caches instead of ~/.cache
|
||||
if (builtin.os.tag == .macos) {
|
||||
// Get our home dir if not provided
|
||||
const home = if (opts.home) |h| h else blk: {
|
||||
var buf: [1024]u8 = undefined;
|
||||
break :blk try homedir.home(&buf) orelse return error.NoHomeDir;
|
||||
};
|
||||
|
||||
return try std.fs.path.join(alloc, &[_][]const u8{
|
||||
home,
|
||||
"Library",
|
||||
"Caches",
|
||||
opts.subdir orelse "",
|
||||
});
|
||||
}
|
||||
|
||||
return try dir(alloc, opts, .{
|
||||
.env = "XDG_CACHE_HOME",
|
||||
.windows_env = "LOCALAPPDATA",
|
||||
@ -143,6 +159,52 @@ test {
|
||||
}
|
||||
}
|
||||
|
||||
test "cache directory paths" {
|
||||
const testing = std.testing;
|
||||
const alloc = testing.allocator;
|
||||
const mock_home = "/Users/test";
|
||||
|
||||
// Test macOS path
|
||||
if (builtin.os.tag == .macos) {
|
||||
// Test base path
|
||||
{
|
||||
const cache_path = try cache(alloc, .{ .home = mock_home });
|
||||
defer alloc.free(cache_path);
|
||||
try testing.expectEqualStrings("/Users/test/Library/Caches", cache_path);
|
||||
}
|
||||
|
||||
// Test with subdir
|
||||
{
|
||||
const cache_path = try cache(alloc, .{
|
||||
.home = mock_home,
|
||||
.subdir = "ghostty",
|
||||
});
|
||||
defer alloc.free(cache_path);
|
||||
try testing.expectEqualStrings("/Users/test/Library/Caches/ghostty", cache_path);
|
||||
}
|
||||
}
|
||||
|
||||
// Test Linux path (when XDG_CACHE_HOME is not set)
|
||||
if (builtin.os.tag == .linux) {
|
||||
// Test base path
|
||||
{
|
||||
const cache_path = try cache(alloc, .{ .home = mock_home });
|
||||
defer alloc.free(cache_path);
|
||||
try testing.expectEqualStrings("/Users/test/.cache", cache_path);
|
||||
}
|
||||
|
||||
// Test with subdir
|
||||
{
|
||||
const cache_path = try cache(alloc, .{
|
||||
.home = mock_home,
|
||||
.subdir = "ghostty",
|
||||
});
|
||||
defer alloc.free(cache_path);
|
||||
try testing.expectEqualStrings("/Users/test/.cache/ghostty", cache_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test parseTerminalExec {
|
||||
const testing = std.testing;
|
||||
|
||||
|
Reference in New Issue
Block a user