mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 20:09:04 +00:00
Use bun.String in mkdir (#3404)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
@@ -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()),
|
||||
};
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user