diff options
author | 2023-06-25 17:54:55 -0700 | |
---|---|---|
committer | 2023-06-25 17:54:55 -0700 | |
commit | f2285a6d71eba0abc27bc449e9a50116447decf8 (patch) | |
tree | 82c43ceac7476a964eabc33b083441bddfebb8b5 /src/bun.js/node/node_fs.zig | |
parent | e682ffb61c8cfd92d0a2787503a5e7ac611dff9e (diff) | |
download | bun-f2285a6d71eba0abc27bc449e9a50116447decf8.tar.gz bun-f2285a6d71eba0abc27bc449e9a50116447decf8.tar.zst bun-f2285a6d71eba0abc27bc449e9a50116447decf8.zip |
Use bun.String in mkdir (#3404)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/node/node_fs.zig')
-rw-r--r-- | src/bun.js/node/node_fs.zig | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index 1298c5d45..13d785e97 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -2368,7 +2368,7 @@ const Return = struct { pub const Lchown = void; pub const Link = void; pub const Lstat = Stats; - pub const Mkdir = string; + pub const Mkdir = bun.String; pub const Mkdtemp = JSC.ZigString; pub const Open = FileDescriptor; pub const WriteFile = void; @@ -2997,7 +2997,7 @@ pub const NodeFS = struct { .sync => { const path = args.path.sliceZ(&this.sync_error_buf); return switch (Syscall.mkdir(path, args.mode)) { - .result => Maybe(Return.Mkdir){ .result = "" }, + .result => Maybe(Return.Mkdir){ .result = bun.String.empty }, .err => |err| Maybe(Return.Mkdir){ .err = err }, }; }, @@ -3031,14 +3031,19 @@ pub const NodeFS = struct { }, .EXIST => { - return Option{ .result = "" }; + return Option{ .result = bun.String.empty }; }, // continue .NOENT => {}, } }, .result => { - return Option{ .result = args.path.slice() }; + return Option{ + .result = if (args.path == .slice_with_underlying_string) + args.path.slice_with_underlying_string.underlying + else + bun.String.create(args.path.slice()), + }; }, } @@ -3111,10 +3116,9 @@ pub const NodeFS = struct { switch (err.getErrno()) { // handle the race condition .EXIST => { - var display_path: []const u8 = ""; + var display_path = bun.String.empty; if (first_match != std.math.maxInt(u16)) { - // TODO: this leaks memory - display_path = bun.default_allocator.dupe(u8, display_path[0..first_match]) catch unreachable; + display_path = bun.String.create(working_mem[0..first_match]); } return Option{ .result = display_path }; }, @@ -3126,12 +3130,14 @@ pub const NodeFS = struct { } }, .result => { - var display_path = args.path.slice(); - if (first_match != std.math.maxInt(u16)) { - // TODO: this leaks memory - display_path = bun.default_allocator.dupe(u8, display_path[0..first_match]) catch unreachable; - } - return Option{ .result = display_path }; + return Option{ + .result = if (first_match != std.math.maxInt(u16)) + bun.String.create(working_mem[0..first_match]) + else if (args.path == .slice_with_underlying_string) + args.path.slice_with_underlying_string.underlying + else + bun.String.create(args.path.slice()), + }; }, } }, |