feat: create parent directories if needed when saving new files

closes #84
This commit is contained in:
CJ van den Berg 2025-07-15 18:07:15 +02:00
parent bc2fbec083
commit b0096bed74
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -1338,6 +1338,8 @@ pub fn store_to_existing_file_const(self: *const Self, file_path: []const u8) St
}
pub fn store_to_new_file_const(self: *const Self, file_path: []const u8) StoreToFileError!void {
if (std.fs.path.dirname(file_path)) |dir_name|
try cwd().makePath(dir_name);
const file = try cwd().createFile(file_path, .{ .read = true, .truncate = true });
defer file.close();
try self.store_to_file_const(file);