From 6058d38f46c5681549798078670a3084b0d75372 Mon Sep 17 00:00:00 2001 From: Bryan Lee <38807139+liby@users.noreply.github.com> Date: Mon, 30 Dec 2024 14:13:22 +0800 Subject: [PATCH] Use bundle ID for macOS cache directory path --- src/crash/sentry.zig | 2 +- src/os/macos.zig | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/crash/sentry.zig b/src/crash/sentry.zig index fba20067d8..f381a88405 100644 --- a/src/crash/sentry.zig +++ b/src/crash/sentry.zig @@ -102,7 +102,7 @@ fn initThread(gpa: Allocator) !void { // Determine the Sentry cache directory. const cache_dir = if (builtin.os.tag == .macos) - try internal_os.macos.cacheDir(alloc, "ghostty/sentry") + try internal_os.macos.cacheDir(alloc, "sentry") else try internal_os.xdg.cache(alloc, .{ .subdir = "ghostty/sentry" }); sentry.c.sentry_options_set_database_path_n( diff --git a/src/os/macos.zig b/src/os/macos.zig index 5cf6ab23a8..918dde9af4 100644 --- a/src/os/macos.zig +++ b/src/os/macos.zig @@ -39,7 +39,10 @@ pub fn cacheDir( alloc: Allocator, sub_path: []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{ @@ -150,14 +153,19 @@ test "cacheDir paths" { { const cache_path = try cacheDir(alloc, ""); 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, build_config.bundle_id) != null); } // Test with subdir { - const cache_path = try cacheDir(alloc, "ghostty"); + const cache_path = try cacheDir(alloc, "test"); 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); } }