Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial fix for #10028 #10030

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,16 @@ pub fn openDirA(dir: std.fs.Dir, path_: []const u8) !std.fs.Dir {
}
}

pub fn openDirForIteration(dir: std.fs.Dir, path_: []const u8) !std.fs.Dir {
if (comptime Environment.isWindows) {
const res = try sys.openDirAtWindowsA(toFD(dir.fd), path_, .{ .iterable = true, .can_rename_or_delete = false, .read_only = true }).unwrap();
return res.asDir();
} else {
const fd = try sys.openatA(toFD(dir.fd), path_, std.os.O.DIRECTORY | std.os.O.CLOEXEC | std.os.O.RDONLY, 0).unwrap();
return fd.asDir();
}
}

pub fn openDirAbsolute(path_: []const u8) !std.fs.Dir {
if (comptime Environment.isWindows) {
const res = try sys.openDirAtWindowsA(invalid_fd, path_, .{ .iterable = true, .can_rename_or_delete = true, .read_only = true }).unwrap();
Expand Down
28 changes: 22 additions & 6 deletions src/resolver/resolver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const JSC = bun.JSC;
const allocators = @import("../allocators.zig");
const Msg = logger.Msg;
const Path = Fs.Path;

const debuglog = Output.scoped(.Resolver, true);
const PackageManager = @import("../install/install.zig").PackageManager;
const Dependency = @import("../install/dependency.zig");
const Install = @import("../install/install.zig");
Expand Down Expand Up @@ -2112,7 +2112,7 @@ pub const Resolver = struct {
var dir_entries_option: *Fs.FileSystem.RealFS.EntriesOption = undefined;
var needs_iter = true;
var in_place: ?*Fs.FileSystem.DirEntry = null;
const open_dir = std.fs.cwd().openDir(dir_path, .{ .iterate = true }) catch |err| {
const open_dir = bun.openDirForIteration(std.fs.cwd(), dir_path) catch |err| {
// TODO: handle this error better
r.log.addErrorFmt(
null,
Expand Down Expand Up @@ -2628,8 +2628,16 @@ pub const Resolver = struct {
};

if (rfs.entries.get(top)) |top_entry| {
bufs(.dir_entry_paths_to_resolve)[@as(usize, @intCast(i))].safe_path = top_entry.entries.dir;
bufs(.dir_entry_paths_to_resolve)[@as(usize, @intCast(i))].fd = top_entry.entries.fd;
switch (top_entry.*) {
.entries => {
bufs(.dir_entry_paths_to_resolve)[@as(usize, @intCast(i))].safe_path = top_entry.entries.dir;
bufs(.dir_entry_paths_to_resolve)[@as(usize, @intCast(i))].fd = top_entry.entries.fd;
},
.err => |err| {
debuglog("Failed to load DirEntry {s} {s} - {s}", .{ top, @errorName(err.original_err), @errorName(err.canonical_error) });
break;
},
}
}
i += 1;
}
Expand All @@ -2645,8 +2653,16 @@ pub const Resolver = struct {
.fd = .zero,
};
if (rfs.entries.get(top)) |top_entry| {
bufs(.dir_entry_paths_to_resolve)[@as(usize, @intCast(i))].safe_path = top_entry.entries.dir;
bufs(.dir_entry_paths_to_resolve)[@as(usize, @intCast(i))].fd = top_entry.entries.fd;
switch (top_entry.*) {
.entries => {
bufs(.dir_entry_paths_to_resolve)[@as(usize, @intCast(i))].safe_path = top_entry.entries.dir;
bufs(.dir_entry_paths_to_resolve)[@as(usize, @intCast(i))].fd = top_entry.entries.fd;
},
.err => |err| {
debuglog("Failed to load DirEntry {s} {s} - {s}", .{ top, @errorName(err.original_err), @errorName(err.canonical_error) });
return err.canonical_error;
},
}
}

i += 1;
Expand Down
Loading