~mil/mepo

13c4a1592436af8948503f3f2fa2dc3b4a7dc523 — Miles Alan a month ago 5c7d678
Add mkdirp_folder_basename and call on filedump
2 files changed, 10 insertions(+), 1 deletions(-)

M src/api/filedump.zig
M src/util/utilfile.zig
M src/api/filedump.zig => src/api/filedump.zig +2 -1
@@ 20,7 20,8 @@ fn execute(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
fn filedump(mepo: *Mepo, filepath: []const u8) !void {
    const expanded_path = try utilfile.wordexp_filepath(mepo.allocator, filepath);
    defer mepo.allocator.free(expanded_path);
    const mepolang_file = try std.fs.openFileAbsolute(expanded_path, .{ .write = true });
    try utilfile.mkdirp_folder_basename(expanded_path);
    const mepolang_file = try std.fs.createFileAbsoluteZ(expanded_path, .{});
    defer mepolang_file.close();

    // Save tables:

M src/util/utilfile.zig => src/util/utilfile.zig +8 -0
@@ 46,3 46,11 @@ pub fn wordexp_filepath(allocator: std.mem.Allocator, path: []const u8) ![:0]con
        return try std.fmt.allocPrintZ(allocator, "{s}", .{expansion.we_wordv[0]});
    }
}


pub fn mkdirp_folder_basename(file_path: []const u8) !void {
    if (std.fs.path.dirname(file_path)) |dir_fp| {
        try std.fs.cwd().makePath(dir_fp);
    }
    return error.DirnameFail;
}