mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
[windows] Use fewer system calls to get the file type in the module resolver
This commit is contained in:
@@ -1272,10 +1272,7 @@ pub const FileSystem = struct {
|
||||
const absolute_path_c: [:0]const u8 = outpath[0..entry_path.len :0];
|
||||
|
||||
if (comptime bun.Environment.isWindows) {
|
||||
var file = try std.fs.openFileAbsoluteZ(absolute_path_c, .{ .mode = .read_only });
|
||||
defer file.close();
|
||||
const metadata = try file.metadata();
|
||||
cache.kind = switch (metadata.kind()) {
|
||||
cache.kind = switch (bun.windows.getFileKindFastA(absolute_path_c)) {
|
||||
.directory => .dir,
|
||||
.sym_link => .file,
|
||||
else => .file,
|
||||
|
||||
@@ -3016,3 +3016,29 @@ pub extern "kernel32" fn GetTempPath2W(
|
||||
nBufferLength: DWORD, // [in]
|
||||
lpBuffer: LPCWSTR, // [out]
|
||||
) DWORD;
|
||||
|
||||
pub fn getFileKindFastA(
|
||||
utf8_path: []const u8,
|
||||
) ?std.fs.File.Kind {
|
||||
var wbuf: bun.WPathBuffer = undefined;
|
||||
const path = bun.strings.toWPath(&wbuf, utf8_path);
|
||||
const attrs = kernel32.GetFileAttributesW(path.ptr);
|
||||
|
||||
if (attrs == INVALID_FILE_ATTRIBUTES) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ((attrs & FILE_ATTRIBUTE_DIRECTORY) != 0) {
|
||||
return .dir;
|
||||
}
|
||||
|
||||
if ((attrs & FILE_ATTRIBUTE_REPARSE_POINT) != 0) {
|
||||
return .sym_link;
|
||||
}
|
||||
|
||||
if ((attrs & FILE_ATTRIBUTE_DEVICE) != 0) {
|
||||
return .char_device;
|
||||
}
|
||||
|
||||
return .file;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user