mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-16 06:46:09 +00:00
crash: prefer XDG cache dir if available
This commit is contained in:
@@ -101,10 +101,23 @@ fn initThread(gpa: Allocator) !void {
|
|||||||
sentry.c.sentry_options_set_before_send(opts, beforeSend, null);
|
sentry.c.sentry_options_set_before_send(opts, beforeSend, null);
|
||||||
|
|
||||||
// Determine the Sentry cache directory.
|
// Determine the Sentry cache directory.
|
||||||
const cache_dir = if (builtin.os.tag == .macos)
|
const cache_dir = cache_dir: {
|
||||||
try internal_os.macos.cacheDir(alloc, "sentry")
|
// On macOS, we prefer to use the NSCachesDirectory value to be
|
||||||
else
|
// a more idiomatic macOS application. But if XDG env vars are set
|
||||||
try internal_os.xdg.cache(alloc, .{ .subdir = "ghostty/sentry" });
|
// we will respect them.
|
||||||
|
if (comptime builtin.os.tag == .macos) macos: {
|
||||||
|
if (std.posix.getenv("XDG_CACHE_HOME") != null) break :macos;
|
||||||
|
break :cache_dir try internal_os.macos.cacheDir(
|
||||||
|
alloc,
|
||||||
|
"sentry",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
break :cache_dir 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(
|
||||||
opts,
|
opts,
|
||||||
cache_dir.ptr,
|
cache_dir.ptr,
|
||||||
|
@@ -25,10 +25,11 @@ pub fn appSupportDir(
|
|||||||
alloc: Allocator,
|
alloc: Allocator,
|
||||||
sub_path: []const u8,
|
sub_path: []const u8,
|
||||||
) AppSupportDirError![]const u8 {
|
) AppSupportDirError![]const u8 {
|
||||||
return try makeCommonPath(alloc, .NSApplicationSupportDirectory, &.{
|
return try commonDir(
|
||||||
build_config.bundle_id,
|
alloc,
|
||||||
sub_path,
|
.NSApplicationSupportDirectory,
|
||||||
});
|
&.{ build_config.bundle_id, sub_path },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const CacheDirError = Allocator.Error || error{AppleAPIFailed};
|
pub const CacheDirError = Allocator.Error || error{AppleAPIFailed};
|
||||||
@@ -39,10 +40,11 @@ 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, &.{
|
return try commonDir(
|
||||||
build_config.bundle_id,
|
alloc,
|
||||||
sub_path,
|
.NSCachesDirectory,
|
||||||
});
|
&.{ build_config.bundle_id, sub_path },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const SetQosClassError = error{
|
pub const SetQosClassError = error{
|
||||||
@@ -101,7 +103,7 @@ pub const NSSearchPathDomainMask = enum(c_ulong) {
|
|||||||
NSUserDomainMask = 1,
|
NSUserDomainMask = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn makeCommonPath(
|
fn commonDir(
|
||||||
alloc: Allocator,
|
alloc: Allocator,
|
||||||
directory: NSSearchPathDirectory,
|
directory: NSSearchPathDirectory,
|
||||||
sub_paths: []const []const u8,
|
sub_paths: []const []const u8,
|
||||||
|
Reference in New Issue
Block a user