mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
config: use dirname so we don't have to alloc a new dir for edit
This commit is contained in:
@ -5,23 +5,21 @@ const internal_os = @import("../os/main.zig");
|
|||||||
/// Open the configuration in the OS default editor according to the default
|
/// Open the configuration in the OS default editor according to the default
|
||||||
/// paths the main config file could be in.
|
/// paths the main config file could be in.
|
||||||
pub fn open(alloc_gpa: Allocator) !void {
|
pub fn open(alloc_gpa: Allocator) !void {
|
||||||
// default dir
|
|
||||||
const config_dir = try internal_os.xdg.config(alloc_gpa, .{ .subdir = "ghostty" });
|
|
||||||
// default location
|
// default location
|
||||||
const config_path = try internal_os.xdg.config(alloc_gpa, .{ .subdir = "ghostty/config" });
|
const config_path = try internal_os.xdg.config(alloc_gpa, .{ .subdir = "ghostty/config" });
|
||||||
|
defer alloc_gpa.free(config_path);
|
||||||
|
|
||||||
defer {
|
// Check if the directory exists, create it if it doesn't. This dirname
|
||||||
alloc_gpa.free(config_path);
|
// call should always succeed but we still check for errors just in case,
|
||||||
alloc_gpa.free(config_dir);
|
// no harm if we skip this step the open may just fail.
|
||||||
}
|
if (std.fs.path.dirname(config_path)) |config_dir| {
|
||||||
|
|
||||||
// Check if the directory exists, create it if it doesn't
|
|
||||||
_ = std.fs.makeDirAbsolute(config_dir) catch |err| {
|
_ = std.fs.makeDirAbsolute(config_dir) catch |err| {
|
||||||
switch (err) {
|
switch (err) {
|
||||||
error.PathAlreadyExists => {},
|
error.PathAlreadyExists => {},
|
||||||
else => return err,
|
else => return err,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Try to create file and go on if it already exists
|
// Try to create file and go on if it already exists
|
||||||
_ = std.fs.createFileAbsolute(
|
_ = std.fs.createFileAbsolute(
|
||||||
|
Reference in New Issue
Block a user