normalize

This commit is contained in:
Dylan Conway
2024-11-01 23:00:21 -07:00
parent 3eeef3f8c7
commit daecb24578
2 changed files with 52 additions and 2 deletions

View File

@@ -8367,7 +8367,13 @@ pub const PackageManager = struct {
fn httpThreadOnInitError(err: HTTP.InitError, opts: HTTP.HTTPThread.InitOpts) noreturn {
switch (err) {
error.LoadCAFile => {
if (!bun.sys.existsZ(opts.abs_ca_file_name)) {
var buf: if (Environment.isWindows) bun.path.PosixToWinNormalizer else void = undefined;
const path = if (comptime Environment.isWindows)
buf.resolveZ(FileSystem.instance.top_level_dir, opts.abs_ca_file_name)
else
opts.abs_ca_file_name;
if (!bun.sys.existsZ(path)) {
Output.err("HTTPThread", "could not find CA file: '{s}'", .{opts.abs_ca_file_name});
} else {
Output.err("HTTPThread", "invalid CA file: '{s}'", .{opts.abs_ca_file_name});
@@ -14851,7 +14857,14 @@ pub const PackageManager = struct {
const original_path = this_bundler.env.get("PATH") orelse "";
var PATH = try std.ArrayList(u8).initCapacity(bun.default_allocator, original_path.len + 1 + "node_modules/.bin".len + cwd.len + 1);
var current_dir: ?*DirInfo = this_bundler.resolver.readDirInfo(cwd) catch null;
var current_dir: ?*DirInfo = this_bundler.resolver.readDirInfo(cwd) catch |err| {
Output.err(err, "failed to read directory '{s}'", .{cwd});
Global.crash();
};
if (current_dir == null) {
Output.errGeneric("directory does not exist: '{s}'", .{cwd});
Global.crash();
}
bun.assert(current_dir != null);
while (current_dir) |dir| {
if (PATH.items.len > 0 and PATH.items[PATH.items.len - 1] != std.fs.path.delimiter) {

View File

@@ -1902,6 +1902,14 @@ pub const PosixToWinNormalizer = struct {
return resolveWithExternalBuf(&this._raw_bytes, source_dir, maybe_posix_path);
}
pub inline fn resolveZ(
this: *PosixToWinNormalizer,
source_dir: []const u8,
maybe_posix_path: []const u8,
) [:0]const u8 {
return resolveWithExternalBufZ(&this._raw_bytes, source_dir, maybe_posix_path);
}
pub inline fn resolveCWD(
this: *PosixToWinNormalizer,
maybe_posix_path: []const u8,
@@ -1943,6 +1951,35 @@ pub const PosixToWinNormalizer = struct {
return maybe_posix_path;
}
fn resolveWithExternalBufZ(
buf: *Buf,
source_dir: []const u8,
maybe_posix_path: []const u8,
) [:0]const u8 {
assert(std.fs.path.isAbsoluteWindows(maybe_posix_path));
if (bun.Environment.isWindows) {
const root = windowsFilesystemRoot(maybe_posix_path);
if (root.len == 1) {
assert(isSepAny(root[0]));
if (bun.strings.isWindowsAbsolutePathMissingDriveLetter(u8, maybe_posix_path)) {
const source_root = windowsFilesystemRoot(source_dir);
@memcpy(buf[0..source_root.len], source_root);
@memcpy(buf[source_root.len..][0 .. maybe_posix_path.len - 1], maybe_posix_path[1..]);
buf[source_root.len + maybe_posix_path.len - 1] = 0;
const res = buf[0 .. source_root.len + maybe_posix_path.len - 1 :0];
assert(!bun.strings.isWindowsAbsolutePathMissingDriveLetter(u8, res));
assert(std.fs.path.isAbsoluteWindows(res));
return res;
}
}
assert(!bun.strings.isWindowsAbsolutePathMissingDriveLetter(u8, maybe_posix_path));
}
@memcpy(buf[0..maybe_posix_path.len], maybe_posix_path);
buf[maybe_posix_path.len] = 0;
return buf[0..maybe_posix_path.len :0];
}
pub fn resolveCWDWithExternalBuf(
buf: *Buf,
maybe_posix_path: []const u8,