summaryrefslogtreecommitdiff
path: root/src/fs.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs.zig')
-rw-r--r--src/fs.zig19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/fs.zig b/src/fs.zig
index fc3eb98f..1d0bbc22 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -637,6 +637,25 @@ test "a path with a part over 255 bytes is NameTooLong, never a panic" {
try std.testing.expectError(error.NameTooLong, statPath(std.testing.io, long, .{}));
}
+/// Make `dir` and each directory above it that is missing, as `mkdir -p`
+/// does: one already there is no failure. A failure shows at the open
+/// that follows.
+pub fn makeDirs(dir: []const u8) void {
+ if (comptime !platform_has_fs) return;
+ var z: [4096:0]u8 = undefined;
+ if (dir.len == 0 or dir.len >= z.len) return;
+ @memcpy(z[0..dir.len], dir);
+ z[dir.len] = 0;
+ pardes.turn.yield();
+ defer pardes.turn.back();
+ for (z[1..dir.len], 1..) |c, i| if (c == '/') {
+ z[i] = 0;
+ _ = libc.mkdir(z[0..i :0], 0o755);
+ z[i] = '/';
+ };
+ _ = libc.mkdir(z[0..dir.len :0], 0o755);
+}
+
pub fn localPath(path: []const u8) ?[]const u8 {
if (std.mem.eql(u8, path, "/n/os")) return "/";
if (std.mem.startsWith(u8, path, "/n/os/")) return path[5..];