aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/node/node_fs.zig32
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()),
+ };
},
}
},