mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
chore(zig): add a new lint for using bun.FD.cwd() (#10683)
This commit is contained in:
@@ -8,5 +8,6 @@
|
||||
"std.mem.indexOfAny": "Use bun.strings.indexAny or bun.strings.indexAnyComptime",
|
||||
"undefined != ": "This is by definition Undefined Behavior.",
|
||||
"undefined == ": "This is by definition Undefined Behavior.",
|
||||
"bun.toFD(std.fs.cwd().fd)": "Use bun.FD.cwd()",
|
||||
"": ""
|
||||
}
|
||||
|
||||
@@ -563,7 +563,7 @@ pub const StandaloneModuleGraph = struct {
|
||||
|
||||
bun.C.moveFileZWithHandle(
|
||||
fd,
|
||||
bun.toFD(std.fs.cwd().fd),
|
||||
bun.FD.cwd(),
|
||||
bun.sliceTo(&(try std.os.toPosixPath(temp_location)), 0),
|
||||
bun.toFD(root_dir.fd),
|
||||
bun.sliceTo(&(try std.os.toPosixPath(std.fs.path.basename(outfile))), 0),
|
||||
|
||||
@@ -548,10 +548,10 @@ pub const RuntimeTranspilerCache = struct {
|
||||
break :brk try bun.toLibUVOwnedFD(dir.fd);
|
||||
}
|
||||
|
||||
break :brk bun.toFD(std.fs.cwd().fd);
|
||||
break :brk bun.FD.cwd();
|
||||
};
|
||||
defer {
|
||||
if (cache_dir_fd != bun.toFD(std.fs.cwd().fd)) _ = bun.sys.close(cache_dir_fd);
|
||||
if (cache_dir_fd != bun.FD.cwd()) _ = bun.sys.close(cache_dir_fd);
|
||||
}
|
||||
|
||||
try Entry.save(
|
||||
|
||||
@@ -826,7 +826,7 @@ pub fn getMain(
|
||||
}
|
||||
|
||||
const fd = bun.sys.openatA(
|
||||
if (comptime Environment.isWindows) bun.invalid_fd else bun.toFD(std.fs.cwd().fd),
|
||||
if (comptime Environment.isWindows) bun.invalid_fd else bun.FD.cwd(),
|
||||
vm.main,
|
||||
|
||||
// Open with the minimum permissions necessary for resolving the file path.
|
||||
|
||||
@@ -2867,7 +2867,7 @@ pub const Arguments = struct {
|
||||
.flag = flag,
|
||||
.mode = mode,
|
||||
.data = data,
|
||||
.dirfd = bun.toFD(std.fs.cwd().fd),
|
||||
.dirfd = bun.FD.cwd(),
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -4803,7 +4803,7 @@ pub const NodeFS = struct {
|
||||
) Maybe(void) {
|
||||
const flags = os.O.DIRECTORY | os.O.RDONLY;
|
||||
|
||||
const atfd = if (comptime is_root) bun.toFD(std.fs.cwd().fd) else async_task.root_fd;
|
||||
const atfd = if (comptime is_root) bun.FD.cwd() else async_task.root_fd;
|
||||
const fd = switch (switch (Environment.os) {
|
||||
else => Syscall.openat(atfd, basename, flags, 0),
|
||||
// windows bun.sys.open does not pass iterable=true,
|
||||
@@ -4953,7 +4953,7 @@ pub const NodeFS = struct {
|
||||
}
|
||||
|
||||
const flags = os.O.DIRECTORY | os.O.RDONLY;
|
||||
const fd = switch (Syscall.openat(if (root_fd == bun.invalid_fd) bun.toFD(std.fs.cwd().fd) else root_fd, basename, flags, 0)) {
|
||||
const fd = switch (Syscall.openat(if (root_fd == bun.invalid_fd) bun.FD.cwd() else root_fd, basename, flags, 0)) {
|
||||
.err => |err| {
|
||||
if (root_fd == bun.invalid_fd) {
|
||||
return .{
|
||||
@@ -5101,7 +5101,7 @@ pub const NodeFS = struct {
|
||||
const fd = switch (switch (Environment.os) {
|
||||
else => Syscall.open(path, flags, 0),
|
||||
// windows bun.sys.open does not pass iterable=true,
|
||||
.windows => bun.sys.openDirAtWindowsA(bun.toFD(std.fs.cwd().fd), path, .{ .iterable = true, .read_only = true }),
|
||||
.windows => bun.sys.openDirAtWindowsA(bun.FD.cwd(), path, .{ .iterable = true, .read_only = true }),
|
||||
}) {
|
||||
.err => |err| return .{
|
||||
.err = err.withPath(args.path.slice()),
|
||||
@@ -6555,7 +6555,7 @@ pub const NodeFS = struct {
|
||||
}
|
||||
|
||||
const open_flags = os.O.DIRECTORY | os.O.RDONLY;
|
||||
const fd = switch (Syscall.openatOSPath(bun.toFD(std.fs.cwd().fd), src, open_flags, 0)) {
|
||||
const fd = switch (Syscall.openatOSPath(bun.FD.cwd(), src, open_flags, 0)) {
|
||||
.err => |err| {
|
||||
task.finishConcurrently(.{ .err = err.withPath(this.osPathIntoSyncErrorBuf(src)) });
|
||||
return false;
|
||||
|
||||
@@ -92,7 +92,7 @@ pub const PathWatcherManager = struct {
|
||||
switch (switch (Environment.os) {
|
||||
else => bun.sys.open(path, std.os.O.DIRECTORY | std.os.O.RDONLY, 0),
|
||||
// windows bun.sys.open does not pass iterable=true,
|
||||
.windows => bun.sys.openDirAtWindowsA(bun.toFD(std.fs.cwd().fd), path, .{ .iterable = true, .read_only = true }),
|
||||
.windows => bun.sys.openDirAtWindowsA(bun.FD.cwd(), path, .{ .iterable = true, .read_only = true }),
|
||||
}) {
|
||||
.err => |e| {
|
||||
if (e.errno == @intFromEnum(bun.C.E.NOTDIR)) {
|
||||
|
||||
@@ -68,6 +68,7 @@ else if (Environment.isWindows)
|
||||
else
|
||||
std.os.fd_t;
|
||||
|
||||
pub const FD = FileDescriptor;
|
||||
pub const FileDescriptor = enum(FileDescriptorInt) {
|
||||
/// Zero is used in old filesystem code to indicate "no file descriptor"
|
||||
/// This is problematic because on POSIX, this is ambiguous with stdin being 0.
|
||||
|
||||
@@ -148,7 +148,7 @@ pub const BunxCommand = struct {
|
||||
bun.pathLiteral("{s}/package.json"),
|
||||
.{tempdir_name},
|
||||
) catch unreachable;
|
||||
const target_package_json_fd = bun.sys.openat(bun.toFD(std.fs.cwd().fd), subpath_z, std.os.O.RDONLY, 0).unwrap() catch return error.NeedToInstall;
|
||||
const target_package_json_fd = bun.sys.openat(bun.FD.cwd(), subpath_z, std.os.O.RDONLY, 0).unwrap() catch return error.NeedToInstall;
|
||||
const target_package_json = bun.sys.File{ .handle = target_package_json_fd };
|
||||
|
||||
const is_stale = is_stale: {
|
||||
@@ -186,7 +186,7 @@ pub const BunxCommand = struct {
|
||||
.{ tempdir_name, package_name },
|
||||
) catch unreachable;
|
||||
|
||||
return try getBinNameFromSubpath(bundler, bun.toFD(std.fs.cwd().fd), subpath_z);
|
||||
return try getBinNameFromSubpath(bundler, bun.FD.cwd(), subpath_z);
|
||||
}
|
||||
|
||||
/// Check the enclosing package.json for a matching "bin"
|
||||
|
||||
@@ -683,7 +683,7 @@ pub const FileSystem = struct {
|
||||
bun.assert(this.fd != bun.invalid_fd);
|
||||
bun.assert(this.dir_fd != bun.invalid_fd);
|
||||
|
||||
try C.moveFileZWithHandle(this.fd, this.dir_fd, bun.sliceTo(from_name, 0), bun.toFD(std.fs.cwd().fd), bun.sliceTo(name, 0));
|
||||
try C.moveFileZWithHandle(this.fd, this.dir_fd, bun.sliceTo(from_name, 0), bun.FD.cwd(), bun.sliceTo(name, 0));
|
||||
this.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ pub const FolderResolution = union(Tag) {
|
||||
defer Npm.Registry.BodyPool.release(body);
|
||||
|
||||
const source = brk: {
|
||||
var file = bun.sys.File.from(try bun.sys.openatA(bun.toFD(std.fs.cwd().fd), abs, std.os.O.RDONLY, 0).unwrap());
|
||||
var file = bun.sys.File.from(try bun.sys.openatA(bun.FD.cwd(), abs, std.os.O.RDONLY, 0).unwrap());
|
||||
defer file.close();
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user