Use bundle ID for macOS cache directory path

This commit is contained in:
Bryan Lee
2024-12-30 14:13:22 +08:00
parent 67794d3f6f
commit 9f44ec7c21
2 changed files with 13 additions and 5 deletions

View File

@ -102,7 +102,7 @@ fn initThread(gpa: Allocator) !void {
// Determine the Sentry cache directory. // Determine the Sentry cache directory.
const cache_dir = if (builtin.os.tag == .macos) const cache_dir = if (builtin.os.tag == .macos)
try internal_os.macos.cacheDir(alloc, "ghostty/sentry") try internal_os.macos.cacheDir(alloc, "sentry")
else else
try internal_os.xdg.cache(alloc, .{ .subdir = "ghostty/sentry" }); try internal_os.xdg.cache(alloc, .{ .subdir = "ghostty/sentry" });
sentry.c.sentry_options_set_database_path_n( sentry.c.sentry_options_set_database_path_n(

View File

@ -39,7 +39,10 @@ pub fn cacheDir(
alloc: Allocator, alloc: Allocator,
sub_path: []const u8, sub_path: []const u8,
) CacheDirError![]const u8 { ) CacheDirError![]const u8 {
return try makeCommonPath(alloc, .NSCachesDirectory, &.{sub_path}); return try makeCommonPath(alloc, .NSCachesDirectory, &.{
build_config.bundle_id,
sub_path,
});
} }
pub const SetQosClassError = error{ pub const SetQosClassError = error{
@ -150,14 +153,19 @@ test "cacheDir paths" {
{ {
const cache_path = try cacheDir(alloc, ""); const cache_path = try cacheDir(alloc, "");
defer alloc.free(cache_path); defer alloc.free(cache_path);
// We don't test the exact path since it comes from NSFileManager
try testing.expect(std.mem.indexOf(u8, cache_path, "Caches") != null); try testing.expect(std.mem.indexOf(u8, cache_path, "Caches") != null);
try testing.expect(std.mem.indexOf(u8, cache_path, build_config.bundle_id) != null);
} }
// Test with subdir // Test with subdir
{ {
const cache_path = try cacheDir(alloc, "ghostty"); const cache_path = try cacheDir(alloc, "test");
defer alloc.free(cache_path); defer alloc.free(cache_path);
try testing.expect(std.mem.indexOf(u8, cache_path, "Caches/ghostty") != null); try testing.expect(std.mem.indexOf(u8, cache_path, "Caches") != null);
try testing.expect(std.mem.indexOf(u8, cache_path, build_config.bundle_id) != null);
const bundle_path = try std.fmt.allocPrint(alloc, "{s}/test", .{build_config.bundle_id});
defer alloc.free(bundle_path);
try testing.expect(std.mem.indexOf(u8, cache_path, bundle_path) != null);
} }
} }