get node:fs tests passing part 1 (#16270)

This commit is contained in:
chloe caruso
2025-01-14 20:53:02 -08:00
committed by GitHub
parent 4e193b0ebd
commit 834ad11d48
126 changed files with 5137 additions and 2415 deletions

View File

@@ -75,7 +75,7 @@ pub const PatchFile = struct {
}
};
pub fn apply(this: *const PatchFile, allocator: Allocator, patch_dir: bun.FileDescriptor) ?JSC.SystemError {
pub fn apply(this: *const PatchFile, allocator: Allocator, patch_dir: bun.FileDescriptor) ?bun.sys.Error {
var state: ApplyState = .{};
var sfb = std.heap.stackFallback(1024, allocator);
var arena = bun.ArenaAllocator.init(sfb.get());
@@ -87,7 +87,7 @@ pub const PatchFile = struct {
const pathz = arena.allocator().dupeZ(u8, part.file_deletion.path) catch bun.outOfMemory();
if (bun.sys.unlinkat(patch_dir, pathz).asErr()) |e| {
return e.withPath(pathz).toSystemError();
return e.withPath(pathz);
}
},
.file_rename => {
@@ -97,7 +97,7 @@ pub const PatchFile = struct {
if (std.fs.path.dirname(to_path)) |todir| {
const abs_patch_dir = switch (state.patchDirAbsPath(patch_dir)) {
.result => |p| p,
.err => |e| return e.toSystemError(),
.err => |e| return e,
};
const path_to_make = bun.path.joinZ(&[_][]const u8{
abs_patch_dir,
@@ -108,11 +108,11 @@ pub const PatchFile = struct {
.path = .{ .string = bun.PathString.init(path_to_make) },
.recursive = true,
.mode = 0o755,
}, .sync).asErr()) |e| return e.toSystemError();
}).asErr()) |e| return e;
}
if (bun.sys.renameat(patch_dir, from_path, patch_dir, to_path).asErr()) |e| {
return e.toSystemError();
return e;
}
},
.file_creation => {
@@ -126,7 +126,7 @@ pub const PatchFile = struct {
.path = .{ .string = bun.PathString.init(filedir) },
.recursive = true,
.mode = @intCast(@intFromEnum(mode)),
}, .sync).asErr()) |e| return e.toSystemError();
}).asErr()) |e| return e;
}
const newfile_fd = switch (bun.sys.openat(
@@ -136,7 +136,7 @@ pub const PatchFile = struct {
mode.toBunMode(),
)) {
.result => |fd| fd,
.err => |e| return e.withPath(filepath.slice()).toSystemError(),
.err => |e| return e.withPath(filepath.slice()),
};
defer _ = bun.sys.close(newfile_fd);
@@ -180,14 +180,14 @@ pub const PatchFile = struct {
while (written < file_contents.len) {
switch (bun.sys.write(newfile_fd, file_contents[written..])) {
.result => |bytes| written += bytes,
.err => |e| return e.withPath(filepath.slice()).toSystemError(),
.err => |e| return e.withPath(filepath.slice()),
}
}
},
.file_patch => {
// TODO: should we compute the hash of the original file and check it against the on in the patch?
if (applyPatch(part.file_patch, &arena, patch_dir, &state).asErr()) |e| {
return e.toSystemError();
return e;
}
},
.file_mode_change => {
@@ -195,22 +195,22 @@ pub const PatchFile = struct {
const filepath = arena.allocator().dupeZ(u8, part.file_mode_change.path) catch bun.outOfMemory();
if (comptime bun.Environment.isPosix) {
if (bun.sys.fchmodat(patch_dir, filepath, newmode.toBunMode(), 0).asErr()) |e| {
return e.toSystemError();
return e;
}
}
if (comptime bun.Environment.isWindows) {
const absfilepath = switch (state.patchDirAbsPath(patch_dir)) {
.result => |p| p,
.err => |e| return e.toSystemError(),
.err => |e| return e,
};
const fd = switch (bun.sys.open(bun.path.joinZ(&[_][]const u8{ absfilepath, filepath }, .auto), bun.O.RDWR, 0)) {
.err => |e| return e.toSystemError(),
.err => |e| return e,
.result => |f| f,
};
defer _ = bun.sys.close(fd);
if (bun.sys.fchmod(fd, newmode.toBunMode()).asErr()) |e| {
return e.toSystemError();
return e;
}
}
},
@@ -1150,7 +1150,7 @@ pub const TestingAPIs = struct {
defer args.deinit();
if (args.patchfile.apply(bun.default_allocator, args.dirfd)) |err| {
return globalThis.throwValue(err.toErrorInstance(globalThis));
return globalThis.throwValue(err.toJSC(globalThis));
}
return .true;