Compare commits

...

1 Commits

Author SHA1 Message Date
Jarred Sumner
432116f76a [windows] Use fewer system calls to get the file type in the module resolver 2024-01-24 21:50:59 -08:00
2 changed files with 27 additions and 4 deletions

View File

@@ -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,

View 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;
}