Skip to content

Commit

Permalink
Look for config file in xdg path
Browse files Browse the repository at this point in the history
  • Loading branch information
adamws committed Nov 11, 2024
1 parent 281f703 commit abd0614
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -444,17 +444,33 @@ pub fn main() !void {

// config handling

const executable_dir = try known_folders.getPath(allocator, .executable_dir) orelse unreachable;
defer allocator.free(executable_dir);
std.debug.print("executable_dir {s}\n", .{executable_dir});

// config parse:
// TODO: for now look for config file only in executable dir, later should use XDG rules
const config_dir = executable_dir;
// use '\0' terminated alloc because this will be passed to inotify syscalls (in c)
const config_path = try std.fmt.allocPrintZ(allocator, "{s}/config", .{config_dir});
const config_path = blk: {
const executable_dir = try known_folders.getPath(allocator, .executable_dir) orelse unreachable;
defer allocator.free(executable_dir);
std.debug.print("executable_dir {s}\n", .{executable_dir});

// use '\0' terminated alloc because this will be passed to inotify syscalls (in c)
var conf = try std.fmt.allocPrintZ(allocator, "{s}/config", .{executable_dir});
if (cwd.openFile(conf, .{})) |file| {
file.close();
std.debug.print("Use config file from executable directory\n", .{});
break :blk conf;
} else |_| {
allocator.free(conf);

// check in local configuration dir
const local_configuration_dir = try known_folders.getPath(allocator, .local_configuration) orelse unreachable;
defer allocator.free(local_configuration_dir);
std.debug.print("local_configuration_dir {s}\n", .{local_configuration_dir});

conf = try std.fmt.allocPrintZ(allocator, "{s}/klawa/config", .{local_configuration_dir});
break :blk conf;
}
};
defer allocator.free(config_path);

const config_dir = fs.path.dirname(config_path) orelse "";

var app_config = config.configManager(ConfigData, allocator);
defer app_config.deinit();

Expand Down

0 comments on commit abd0614

Please sign in to comment.