@@ -59,7 +59,7 @@ pub fn main() !void {
5959 var port_override : ? u16 = null ;
6060 var db_override : ? [:0 ]const u8 = null ;
6161 var token_override : ? []const u8 = null ;
62- var config_path : []const u8 = "config.json" ;
62+ var config_path_override : ? []const u8 = null ;
6363
6464 var i : usize = 0 ;
6565 while (i < all_args .len ) : (i += 1 ) {
@@ -90,7 +90,7 @@ pub fn main() !void {
9090 } else if (std .mem .eql (u8 , arg , "--config" )) {
9191 i += 1 ;
9292 if (i < all_args .len ) {
93- config_path = all_args [i ];
93+ config_path_override = all_args [i ];
9494 }
9595 } else if (std .mem .eql (u8 , arg , "--version" )) {
9696 std .debug .print ("nullboiler v{s}\n " , .{version });
@@ -101,6 +101,10 @@ pub fn main() !void {
101101 // Load configuration
102102 var cfg_arena = std .heap .ArenaAllocator .init (allocator );
103103 defer cfg_arena .deinit ();
104+ const config_path = config .resolveConfigPath (cfg_arena .allocator (), config_path_override ) catch | err | {
105+ std .debug .print ("failed to resolve config path: {}\n " , .{err });
106+ return ;
107+ };
104108 var cfg = config .loadFromFile (cfg_arena .allocator (), config_path ) catch | err | {
105109 std .debug .print ("failed to load config from {s}: {}\n " , .{ config_path , err });
106110 return ;
@@ -134,6 +138,11 @@ pub fn main() !void {
134138 std .debug .print ("API auth: disabled\n " , .{});
135139 }
136140
141+ ensureParentDirForFile (db_path ) catch | err | {
142+ std .debug .print ("failed to create database directory for {s}: {}\n " , .{ db_path , err });
143+ return ;
144+ };
145+
137146 var store = try Store .init (allocator , db_path );
138147 defer store .deinit ();
139148 var metrics = metrics_mod.Metrics {};
@@ -396,6 +405,26 @@ pub fn main() !void {
396405 }
397406}
398407
408+ fn ensureParentDirForFile (path : []const u8 ) ! void {
409+ if (path .len == 0 or std .mem .eql (u8 , path , ":memory:" ) or std .mem .startsWith (u8 , path , "file:" )) return ;
410+
411+ const parent = std .fs .path .dirname (path ) orelse return ;
412+ if (parent .len == 0 ) return ;
413+
414+ if (std .fs .path .isAbsolute (parent )) {
415+ std .fs .makeDirAbsolute (parent ) catch | err | switch (err ) {
416+ error .PathAlreadyExists = > {},
417+ else = > return err ,
418+ };
419+ return ;
420+ }
421+
422+ std .fs .cwd ().makePath (parent ) catch | err | switch (err ) {
423+ error .PathAlreadyExists = > {},
424+ else = > return err ,
425+ };
426+ }
427+
399428fn serializeTagsJson (allocator : std.mem.Allocator , tags : []const []const u8 ) ! []const u8 {
400429 return std .json .Stringify .valueAlloc (allocator , tags , .{});
401430}
0 commit comments