Skip to content

Commit

Permalink
Use bundle ID for macOS cache directory path
Browse files Browse the repository at this point in the history
  • Loading branch information
liby committed Jan 2, 2025
1 parent 41da5da commit 6058d38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/crash/sentry.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 12 additions & 4 deletions src/os/macos.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 6058d38

Please sign in to comment.