From ecb6c810c892a4d1c2da7d0515bd3374b4646eb1 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 21 May 2024 15:55:49 -0700 Subject: [PATCH] replace `[bun.MAX_PATH_BYTES]u8` with `bun.PathBuffer` (#11162) --- misctools/readlink-getfd.zig | 4 +- misctools/readlink-realpath.zig | 2 +- misctools/tgz.zig | 2 +- src/StandaloneModuleGraph.zig | 8 ++-- src/allocators.zig | 2 +- src/bun.js/RuntimeTranspilerCache.zig | 14 +++--- src/bun.js/api/BunObject.zig | 6 +-- src/bun.js/api/JSBundler.zig | 2 +- src/bun.js/api/bun/dns_resolver.zig | 4 +- src/bun.js/api/bun/subprocess.zig | 4 +- src/bun.js/api/ffi.zig | 2 +- src/bun.js/api/filesystem_router.zig | 4 +- src/bun.js/api/glob.zig | 2 +- src/bun.js/api/server.zig | 2 +- src/bun.js/bindings/bindings.zig | 2 +- src/bun.js/javascript.zig | 4 +- src/bun.js/module_loader.zig | 6 +-- src/bun.js/node/node_fs.zig | 40 ++++++++-------- src/bun.js/node/path_watcher.zig | 4 +- src/bun.js/node/win_watcher.zig | 2 +- src/bun.js/test/snapshot.zig | 4 +- src/bun.js/webcore/blob.zig | 22 ++++----- src/bun.js/webcore/response.zig | 6 +-- src/bun.js/webcore/streams.zig | 2 +- src/bundler.zig | 8 ++-- src/bundler/bundle_v2.zig | 8 ++-- src/bundler/entry_points.zig | 4 +- src/cli.zig | 12 ++--- src/cli/build_command.zig | 6 +-- src/cli/bunx_command.zig | 6 +-- src/cli/create_command.zig | 4 +- src/cli/exec_command.zig | 2 +- src/cli/install_completions_command.zig | 10 ++-- src/cli/package_manager_command.zig | 10 ++-- src/cli/run_command.zig | 6 +-- src/cli/test_command.zig | 8 ++-- src/cli/upgrade_command.zig | 8 ++-- src/env_loader.zig | 2 +- src/fs.zig | 12 ++--- src/glob.zig | 16 +++---- src/install/bin.zig | 10 ++-- src/install/install.zig | 48 +++++++++---------- src/install/lockfile.zig | 4 +- src/install/migration.zig | 2 +- src/install/repository.zig | 6 +-- src/install/resolvers/folder_resolver.zig | 6 +-- src/open.zig | 10 ++-- src/resolver/package_json.zig | 10 ++-- src/resolver/resolve_path.zig | 2 +- src/resolver/resolver.zig | 50 +++++++++---------- src/runtime.zig | 4 +- src/shell/interpreter.zig | 58 +++++++++++------------ src/sourcemap/sourcemap.zig | 2 +- src/string_immutable.zig | 4 +- src/sys.zig | 2 +- src/which.zig | 2 +- 56 files changed, 246 insertions(+), 246 deletions(-) diff --git a/misctools/readlink-getfd.zig b/misctools/readlink-getfd.zig index 36d6ef6583f55a..93fb93be3163ec 100644 --- a/misctools/readlink-getfd.zig +++ b/misctools/readlink-getfd.zig @@ -29,12 +29,12 @@ pub fn main() anyerror!void { const to_resolve = args[args.len - 1]; const cwd = try bun.getcwdAlloc(allocator); var path: []u8 = undefined; - var out_buffer: [bun.MAX_PATH_BYTES]u8 = undefined; + var out_buffer: bun.PathBuffer = undefined; var j: usize = 0; while (j < 1000) : (j += 1) { var parts = [1][]const u8{to_resolve}; - var joined_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var joined_buf: bun.PathBuffer = undefined; var joined = path_handler.joinAbsStringBuf( cwd, &joined_buf, diff --git a/misctools/readlink-realpath.zig b/misctools/readlink-realpath.zig index 905f4394c0f782..1891e30f0b3ac4 100644 --- a/misctools/readlink-realpath.zig +++ b/misctools/readlink-realpath.zig @@ -27,7 +27,7 @@ pub fn main() anyerror!void { var args = std.mem.bytesAsSlice([]u8, try std.process.argsAlloc(allocator)); const to_resolve = args[args.len - 1]; - var out_buffer: [bun.MAX_PATH_BYTES]u8 = undefined; + var out_buffer: bun.PathBuffer = undefined; var path: []u8 = undefined; var j: usize = 0; diff --git a/misctools/tgz.zig b/misctools/tgz.zig index 45ff04f37ac0fd..780b02fad540a9 100644 --- a/misctools/tgz.zig +++ b/misctools/tgz.zig @@ -37,7 +37,7 @@ pub fn main() anyerror!void { Global.exit(1); } - var tarball_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var tarball_path_buf: bun.PathBuffer = undefined; var basename = std.fs.path.basename(bun.asByteSlice(args[args.len - 1])); while (RecognizedExtensions.has(std.fs.path.extension(basename))) { basename = basename[0 .. basename.len - std.fs.path.extension(basename).len]; diff --git a/src/StandaloneModuleGraph.zig b/src/StandaloneModuleGraph.zig index 64e4d93874bf50..cd9bf871659af0 100644 --- a/src/StandaloneModuleGraph.zig +++ b/src/StandaloneModuleGraph.zig @@ -55,7 +55,7 @@ pub const StandaloneModuleGraph = struct { return null; } if (Environment.isWindows) { - var normalized_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var normalized_buf: bun.PathBuffer = undefined; const normalized = bun.path.platformToPosixBuf(u8, name, &normalized_buf); return this.files.getPtr(normalized); } @@ -262,7 +262,7 @@ pub const StandaloneModuleGraph = struct { std.mem.page_size; pub fn inject(bytes: []const u8, self_exe: [:0]const u8) bun.FileDescriptor { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; var zname: [:0]const u8 = bun.span(bun.fs.FileSystem.instance.tmpname("bun-build", &buf, @as(u64, @bitCast(std.time.milliTimestamp()))) catch |err| { Output.prettyErrorln("error: failed to get temporary file name: {s}", .{@errorName(err)}); Global.exit(1); @@ -532,7 +532,7 @@ pub const StandaloneModuleGraph = struct { return; } - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const temp_location = bun.getFdPath(fd, &buf) catch |err| { Output.prettyErrorln("error: failed to get path for fd: {s}", .{@errorName(err)}); Global.exit(1); @@ -727,7 +727,7 @@ pub const StandaloneModuleGraph = struct { } else |_| { if (bun.argv.len > 0) { // The user doesn't have /proc/ mounted, so now we just guess and hope for the best. - var whichbuf: [bun.MAX_PATH_BYTES]u8 = undefined; + var whichbuf: bun.PathBuffer = undefined; if (bun.which( &whichbuf, bun.getenvZ("PATH") orelse return error.FileNotFound, diff --git a/src/allocators.zig b/src/allocators.zig index 66d37f2b43fd39..bc279c27a2d254 100644 --- a/src/allocators.zig +++ b/src/allocators.zig @@ -347,7 +347,7 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type return try self.doAppend(AppendType, _value); } - threadlocal var lowercase_append_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + threadlocal var lowercase_append_buf: bun.PathBuffer = undefined; pub fn appendLowerCase(self: *Self, comptime AppendType: type, _value: AppendType) ![]const u8 { self.mutex.lock(); defer self.mutex.unlock(); diff --git a/src/bun.js/RuntimeTranspilerCache.zig b/src/bun.js/RuntimeTranspilerCache.zig index 06e8ac023f1faf..8ba2fa56c820c5 100644 --- a/src/bun.js/RuntimeTranspilerCache.zig +++ b/src/bun.js/RuntimeTranspilerCache.zig @@ -153,7 +153,7 @@ pub const RuntimeTranspilerCache = struct { defer tracer.end(); // atomically write to a tmpfile and then move it to the final destination - var tmpname_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var tmpname_buf: bun.PathBuffer = undefined; const tmpfilename = bun.sliceTo(try bun.fs.FileSystem.instance.tmpname(std.fs.path.extension(destination_path.slice()), &tmpname_buf, input_hash), 0); const output_bytes = output_code.byteSlice(); @@ -365,7 +365,7 @@ pub const RuntimeTranspilerCache = struct { } pub fn getCacheFilePath( - buf: *[bun.MAX_PATH_BYTES]u8, + buf: *bun.PathBuffer, input_hash: u64, ) ![:0]const u8 { const cache_dir = try getCacheDir(buf); @@ -376,7 +376,7 @@ pub const RuntimeTranspilerCache = struct { return buf[0 .. cache_dir.len + 1 + cache_filename_len :0]; } - fn reallyGetCacheDir(buf: *[bun.MAX_PATH_BYTES]u8) [:0]const u8 { + fn reallyGetCacheDir(buf: *bun.PathBuffer) [:0]const u8 { if (comptime bun.Environment.isDebug) { bun_debug_restore_from_cache = bun.getenvZ("BUN_DEBUG_ENABLE_RESTORE_FROM_TRANSPILER_CACHE") != null; } @@ -424,11 +424,11 @@ pub const RuntimeTranspilerCache = struct { } // Only do this at most once per-thread. - threadlocal var runtime_transpiler_cache_static_buffer: [bun.MAX_PATH_BYTES]u8 = undefined; + threadlocal var runtime_transpiler_cache_static_buffer: bun.PathBuffer = undefined; threadlocal var runtime_transpiler_cache: ?[:0]const u8 = null; pub var is_disabled = false; - fn getCacheDir(buf: *[bun.MAX_PATH_BYTES]u8) ![:0]const u8 { + fn getCacheDir(buf: *bun.PathBuffer) ![:0]const u8 { if (is_disabled) return error.CacheDisabled; const path = runtime_transpiler_cache orelse path: { const path = reallyGetCacheDir(&runtime_transpiler_cache_static_buffer); @@ -454,7 +454,7 @@ pub const RuntimeTranspilerCache = struct { var tracer = bun.tracy.traceNamed(@src(), "RuntimeTranspilerCache.fromFile"); defer tracer.end(); - var cache_file_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var cache_file_path_buf: bun.PathBuffer = undefined; const cache_file_path = try getCacheFilePath(&cache_file_path_buf, input_hash); bun.assert(cache_file_path.len > 0); return fromFileWithCacheFilePath( @@ -528,7 +528,7 @@ pub const RuntimeTranspilerCache = struct { var tracer = bun.tracy.traceNamed(@src(), "RuntimeTranspilerCache.toFile"); defer tracer.end(); - var cache_file_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var cache_file_path_buf: bun.PathBuffer = undefined; const output_code: Entry.OutputCode = switch (source_code.encoding()) { .utf8 => .{ .utf8 = source_code.byteSlice() }, else => .{ .string = source_code }, diff --git a/src/bun.js/api/BunObject.zig b/src/bun.js/api/BunObject.zig index d14d09c4253fa8..6292b5c2dbc232 100644 --- a/src/bun.js/api/BunObject.zig +++ b/src/bun.js/api/BunObject.zig @@ -530,7 +530,7 @@ pub fn which( callframe: *JSC.CallFrame, ) callconv(.C) JSC.JSValue { const arguments_ = callframe.arguments(2); - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; var arguments = JSC.Node.ArgumentsSlice.init(globalThis.bunVM(), arguments_.slice()); defer arguments.deinit(); const path_arg = arguments.nextEat() orelse { @@ -1247,7 +1247,7 @@ pub fn getPublicPathJS(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFr if (arguments.len < 1) { return bun.String.empty.toJS(globalObject); } - var public_path_temp_str: [bun.MAX_PATH_BYTES]u8 = undefined; + var public_path_temp_str: bun.PathBuffer = undefined; const to = arguments[0].toSlice(globalObject, bun.default_allocator); defer to.deinit(); @@ -3269,7 +3269,7 @@ pub fn mmapFile( var args = JSC.Node.ArgumentsSlice.init(globalThis.bunVM(), arguments_.slice()); defer args.deinit(); - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const path = brk: { if (args.nextEat()) |path| { if (path.isString()) { diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig index 259abc90665dd7..b106535ee6b4f5 100644 --- a/src/bun.js/api/JSBundler.zig +++ b/src/bun.js/api/JSBundler.zig @@ -310,7 +310,7 @@ pub const JSBundler = struct { }; defer dir.close(); - var rootdir_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var rootdir_buf: bun.PathBuffer = undefined; this.rootdir.appendSliceExact(try bun.getFdPath(bun.toFD(dir.fd), &rootdir_buf)) catch unreachable; } diff --git a/src/bun.js/api/bun/dns_resolver.zig b/src/bun.js/api/bun/dns_resolver.zig index 984a4407445bb6..68bb704593fb6a 100644 --- a/src/bun.js/api/bun/dns_resolver.zig +++ b/src/bun.js/api/bun/dns_resolver.zig @@ -237,7 +237,7 @@ const LibUVBackend = struct { const port = std.fmt.bufPrintIntToSlice(&port_buf, query.port, 10, .lower, .{}); port_buf[port.len] = 0; const portZ = port_buf[0..port.len :0]; - var hostname: [bun.MAX_PATH_BYTES]u8 = undefined; + var hostname: bun.PathBuffer = undefined; _ = strings.copy(hostname[0..], query.name); hostname[query.name.len] = 0; const host = hostname[0..query.name.len :0]; @@ -758,7 +758,7 @@ pub const GetAddrInfoRequest = struct { const port = std.fmt.bufPrintIntToSlice(&port_buf, query.port, 10, .lower, .{}); port_buf[port.len] = 0; const portZ = port_buf[0..port.len :0]; - var hostname: [bun.MAX_PATH_BYTES]u8 = undefined; + var hostname: bun.PathBuffer = undefined; _ = strings.copy(hostname[0..], query.name); hostname[query.name.len] = 0; var addrinfo: ?*std.c.addrinfo = null; diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index a80325ba5e6d2f..337d092d56e364 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -1714,7 +1714,7 @@ pub const Subprocess = struct { defer arg0.deinit(); if (argv0 == null) { - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; const resolved = Which.which(&path_buf, PATH, cwd, arg0.slice()) orelse { globalThis.throwInvalidArguments("Executable not found in $PATH: \"{s}\"", .{arg0.slice()}); return .zero; @@ -1724,7 +1724,7 @@ pub const Subprocess = struct { return .zero; }; } else { - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; const resolved = Which.which(&path_buf, PATH, cwd, bun.sliceTo(argv0.?, 0)) orelse { globalThis.throwInvalidArguments("Executable not found in $PATH: \"{s}\"", .{arg0.slice()}); return .zero; diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig index 44175c96f37a32..59413cceaa2e61 100644 --- a/src/bun.js/api/ffi.zig +++ b/src/bun.js/api/ffi.zig @@ -282,7 +282,7 @@ pub const FFI = struct { return JSC.toInvalidArguments("Expected an options object with symbol names", .{}, global); } - var filepath_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var filepath_buf: bun.PathBuffer = undefined; const name = brk: { if (JSC.ModuleLoader.resolveEmbeddedFile( vm, diff --git a/src/bun.js/api/filesystem_router.zig b/src/bun.js/api/filesystem_router.zig index fdc9f7319e4773..bd5a22c34d001e 100644 --- a/src/bun.js/api/filesystem_router.zig +++ b/src/bun.js/api/filesystem_router.zig @@ -555,7 +555,7 @@ pub const MatchedRoute = struct { file_path: string, client_framework_enabled: bool, ) void { - var entry_point_tempbuf: [bun.MAX_PATH_BYTES]u8 = undefined; + var entry_point_tempbuf: bun.PathBuffer = undefined; // We don't store the framework config including the client parts in the server // instead, we just store a boolean saying whether we should generate this whenever the script is requested // this is kind of bad. we should consider instead a way to inline the contents of the script. @@ -578,7 +578,7 @@ pub const MatchedRoute = struct { this: *MatchedRoute, globalThis: *JSC.JSGlobalObject, ) callconv(.C) JSC.JSValue { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; var stream = std.io.fixedBufferStream(&buf); var writer = stream.writer(); JSC.API.Bun.getPublicPathWithAssetPrefix( diff --git a/src/bun.js/api/glob.zig b/src/bun.js/api/glob.zig index ee0a6a7043baed..29fdc3f47dafb9 100644 --- a/src/bun.js/api/glob.zig +++ b/src/bun.js/api/glob.zig @@ -64,7 +64,7 @@ const ScanOpts = struct { } // Convert to an absolute path - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; const cwd = switch (bun.sys.getcwd((&path_buf))) { .result => |cwd| cwd, .err => |err| { diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 9cf3d48fc2eba0..298f8f993a1d48 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -2097,7 +2097,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp this.blob = .{ .Blob = blob }; const file = &this.blob.store().?.data.file; - var file_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var file_buf: bun.PathBuffer = undefined; const auto_close = file.pathlike != .fd; const fd = if (!auto_close) file.pathlike.fd diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index f87cb2cb9cc6c1..1aeab7c0bfbaa1 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -820,7 +820,7 @@ pub const ZigString = extern struct { }; } - pub fn sliceZBuf(this: ZigString, buf: *[bun.MAX_PATH_BYTES]u8) ![:0]const u8 { + pub fn sliceZBuf(this: ZigString, buf: *bun.PathBuffer) ![:0]const u8 { return try std.fmt.bufPrintZ(buf, "{}", .{this}); } diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 04e9c38f9ff312..cb6f65308955a2 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -1863,7 +1863,7 @@ pub const VirtualMachine = struct { return specifier; } - threadlocal var specifier_cache_resolver_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + threadlocal var specifier_cache_resolver_buf: bun.PathBuffer = undefined; fn _resolve( ret: *ResolveFunctionResult, specifier: string, @@ -3806,7 +3806,7 @@ pub fn NewHotReloader(comptime Ctx: type, comptime EventLoopType: type, comptime var fs: *Fs.FileSystem = bundler.fs; var rfs: *Fs.FileSystem.RealFS = &fs.fs; var resolver = &bundler.resolver; - var _on_file_update_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var _on_file_update_path_buf: bun.PathBuffer = undefined; var current_task: HotReloadTask = .{ .reloader = this, diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index 7d03dd286fe53a..ce2fb312f1e678 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -118,7 +118,7 @@ fn jsModuleFromFile(from_path: string, comptime input: string) string { }; } else { var parts = [_]string{ from_path, "src/js/out/" ++ moduleFolder ++ "/" ++ input }; - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; var absolute_path_to_use = Fs.FileSystem.instance.absBuf(&parts, &buf); buf[absolute_path_to_use.len] = 0; file = std.fs.openFileAbsoluteZ(absolute_path_to_use[0..absolute_path_to_use.len :0], .{ .mode = .read_only }) catch { @@ -174,7 +174,7 @@ fn dumpSourceString(specifier: string, written: []const u8) void { else => "/tmp/bun-debug-src/", .windows => brk: { const temp = bun.fs.FileSystem.RealFS.platformTempDir(); - var win_temp_buffer: [bun.MAX_PATH_BYTES]u8 = undefined; + var win_temp_buffer: bun.PathBuffer = undefined; @memcpy(win_temp_buffer[0..temp.len], temp); const suffix = "\\bun-debug-src"; @memcpy(win_temp_buffer[temp.len .. temp.len + suffix.len], suffix); @@ -732,7 +732,7 @@ pub const ModuleLoader = struct { } // atomically write to a tmpfile and then move it to the final destination - var tmpname_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var tmpname_buf: bun.PathBuffer = undefined; const tmpfilename = bun.sliceTo(bun.fs.FileSystem.instance.tmpname(extname, &tmpname_buf, bun.hash(file.name)) catch return null, 0); const tmpdir = bun.fs.FileSystem.instance.tmpdir() catch return null; diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index f625b41828c44a..07853d9d73be3f 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -811,7 +811,7 @@ pub const AsyncReaddirRecursiveTask = struct { bun.default_allocator.free(this.basename.sliceAssumeZ()); this.destroy(); } - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; this.readdir_task.performWork(this.basename.sliceAssumeZ(), &buf, false); } }; @@ -858,7 +858,7 @@ pub const AsyncReaddirRecursiveTask = struct { return task.promise.value(); } - pub fn performWork(this: *AsyncReaddirRecursiveTask, basename: [:0]const u8, buf: *[bun.MAX_PATH_BYTES]u8, comptime is_root: bool) void { + pub fn performWork(this: *AsyncReaddirRecursiveTask, basename: [:0]const u8, buf: *bun.PathBuffer, comptime is_root: bool) void { switch (this.args.tag()) { inline else => |tag| { const ResultType = comptime switch (tag) { @@ -915,7 +915,7 @@ pub const AsyncReaddirRecursiveTask = struct { fn workPoolCallback(task: *JSC.WorkPoolTask) void { var this: *AsyncReaddirRecursiveTask = @fieldParentPtr(AsyncReaddirRecursiveTask, "task", task); - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; this.performWork(this.root_path.sliceAssumeZ(), &buf, true); } @@ -4056,7 +4056,7 @@ pub const NodeFS = struct { /// We want to avoid allocating a new path buffer for every error message so that JSC can clone + GC it. /// That means a stack-allocated buffer won't suffice. Instead, we re-use /// the heap allocated buffer on the NodefS struct - sync_error_buf: [bun.MAX_PATH_BYTES]u8 = undefined, + sync_error_buf: bun.PathBuffer = undefined, vm: ?*JSC.VirtualMachine = null, pub const ReturnType = Return; @@ -4219,8 +4219,8 @@ pub const NodeFS = struct { // TODO: do we need to fchown? if (comptime Environment.isMac) { - var src_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - var dest_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var src_buf: bun.PathBuffer = undefined; + var dest_buf: bun.PathBuffer = undefined; const src = args.src.sliceZ(&src_buf); const dest = args.dest.sliceZ(&dest_buf); @@ -4294,8 +4294,8 @@ pub const NodeFS = struct { } if (comptime Environment.isLinux) { - var src_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - var dest_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var src_buf: bun.PathBuffer = undefined; + var dest_buf: bun.PathBuffer = undefined; const src = args.src.sliceZ(&src_buf); const dest = args.dest.sliceZ(&dest_buf); @@ -4576,7 +4576,7 @@ pub const NodeFS = struct { } pub fn link(this: *NodeFS, args: Arguments.Link, comptime _: Flavor) Maybe(Return.Link) { - var new_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var new_path_buf: bun.PathBuffer = undefined; const from = args.old_path.sliceZ(&this.sync_error_buf); const to = args.new_path.sliceZ(&new_path_buf); @@ -4636,13 +4636,13 @@ pub const NodeFS = struct { args.path.osPath(&buf) else brk: { // TODO(@paperdave): clean this up a lot. - var joined_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var joined_buf: bun.PathBuffer = undefined; if (std.fs.path.isAbsolute(args.path.slice())) { const utf8 = PosixToWinNormalizer.resolveCWDWithExternalBufZ(&joined_buf, args.path.slice()) catch return .{ .err = .{ .errno = @intFromEnum(C.SystemErrno.ENOMEM), .syscall = .getcwd } }; break :brk strings.toWPath(&buf, utf8); } else { - var cwd_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var cwd_buf: bun.PathBuffer = undefined; const cwd = std.os.getcwd(&cwd_buf) catch return .{ .err = .{ .errno = @intFromEnum(C.SystemErrno.ENOMEM), .syscall = .getcwd } }; break :brk strings.toWPath(&buf, bun.path.joinAbsStringBuf(cwd, &joined_buf, &.{args.path.slice()}, .windows)); } @@ -5122,7 +5122,7 @@ pub const NodeFS = struct { } pub fn readdirWithEntriesRecursiveAsync( - buf: *[bun.MAX_PATH_BYTES]u8, + buf: *bun.PathBuffer, args: Arguments.Readdir, async_task: *AsyncReaddirRecursiveTask, basename: [:0]const u8, @@ -5256,7 +5256,7 @@ pub const NodeFS = struct { } fn readdirWithEntriesRecursiveSync( - buf: *[bun.MAX_PATH_BYTES]u8, + buf: *bun.PathBuffer, args: Arguments.Readdir, root_basename: [:0]const u8, comptime ExpectedType: type, @@ -5396,7 +5396,7 @@ pub const NodeFS = struct { } fn _readdir( - buf: *[bun.MAX_PATH_BYTES]u8, + buf: *bun.PathBuffer, args: Arguments.Readdir, comptime ExpectedType: type, comptime recursive: bool, @@ -5412,7 +5412,7 @@ pub const NodeFS = struct { const path = args.path.sliceZ(buf); if (comptime recursive and flavor == .sync) { - var buf_to_pass: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf_to_pass: bun.PathBuffer = undefined; var entries = std.ArrayList(ExpectedType).init(bun.default_allocator); return switch (readdirWithEntriesRecursiveSync(&buf_to_pass, args, path, ExpectedType, &entries)) { @@ -5677,7 +5677,7 @@ pub const NodeFS = struct { }; } - pub fn writeFileWithPathBuffer(pathbuf: *[bun.MAX_PATH_BYTES]u8, args: Arguments.WriteFile) Maybe(Return.WriteFile) { + pub fn writeFileWithPathBuffer(pathbuf: *bun.PathBuffer, args: Arguments.WriteFile) Maybe(Return.WriteFile) { const fd = switch (args.file) { .path => brk: { const path = args.file.path.sliceZWithForceCopy(pathbuf, true); @@ -5785,7 +5785,7 @@ pub const NodeFS = struct { } pub fn readlink(this: *NodeFS, args: Arguments.Readlink, comptime _: Flavor) Maybe(Return.Readlink) { - var outbuf: [bun.MAX_PATH_BYTES]u8 = undefined; + var outbuf: bun.PathBuffer = undefined; const inbuf = &this.sync_error_buf; const path = args.path.sliceZ(inbuf); @@ -5853,7 +5853,7 @@ pub const NodeFS = struct { }; } - var outbuf: [bun.MAX_PATH_BYTES]u8 = undefined; + var outbuf: bun.PathBuffer = undefined; var inbuf = &this.sync_error_buf; if (comptime Environment.allow_assert) bun.assert(FileSystem.instance_loaded); @@ -5913,7 +5913,7 @@ pub const NodeFS = struct { pub fn rename(this: *NodeFS, args: Arguments.Rename, comptime flavor: Flavor) Maybe(Return.Rename) { _ = flavor; const from_buf = &this.sync_error_buf; - var to_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var to_buf: bun.PathBuffer = undefined; const from = args.old_path.sliceZ(from_buf); const to = args.new_path.sliceZ(&to_buf); @@ -6088,7 +6088,7 @@ pub const NodeFS = struct { } pub fn symlink(this: *NodeFS, args: Arguments.Symlink, comptime _: Flavor) Maybe(Return.Symlink) { - var to_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var to_buf: bun.PathBuffer = undefined; if (Environment.isWindows) { const target: [:0]u8 = args.old_path.sliceZWithForceCopy(&this.sync_error_buf, true); diff --git a/src/bun.js/node/path_watcher.zig b/src/bun.js/node/path_watcher.zig index 91d11a29f8a540..a54dda7d7eba48 100644 --- a/src/bun.js/node/path_watcher.zig +++ b/src/bun.js/node/path_watcher.zig @@ -173,7 +173,7 @@ pub const PathWatcherManager = struct { var counts = slice.items(.count); const kinds = slice.items(.kind); - var _on_file_update_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var _on_file_update_path_buf: bun.PathBuffer = undefined; var ctx = this.main_watcher; defer ctx.flushEvictions(); @@ -773,7 +773,7 @@ pub const PathWatcher = struct { if (comptime Environment.isMac) { if (!path.is_file) { - var buffer: [bun.MAX_PATH_BYTES]u8 = undefined; + var buffer: bun.PathBuffer = undefined; const resolved_path_temp = std.os.getFdPath(path.fd.cast(), &buffer) catch |err| { bun.default_allocator.destroy(this); return err; diff --git a/src/bun.js/node/win_watcher.zig b/src/bun.js/node/win_watcher.zig index 9d3b806b0732f0..dc4fcbd949bd5d 100644 --- a/src/bun.js/node/win_watcher.zig +++ b/src/bun.js/node/win_watcher.zig @@ -180,7 +180,7 @@ pub const PathWatcher = struct { } pub fn init(manager: *PathWatcherManager, path: [:0]const u8, recursive: bool) bun.JSC.Maybe(*PathWatcher) { - var outbuf: [bun.MAX_PATH_BYTES]u8 = undefined; + var outbuf: bun.PathBuffer = undefined; const event_path = switch (bun.sys.readlink(path, &outbuf)) { .err => |err| brk: { if (err.errno == @intFromEnum(bun.C.E.NOENT)) { diff --git a/src/bun.js/test/snapshot.zig b/src/bun.js/test/snapshot.zig index 62dfc3365171c5..5af8574f989f74 100644 --- a/src/bun.js/test/snapshot.zig +++ b/src/bun.js/test/snapshot.zig @@ -108,7 +108,7 @@ pub const Snapshots = struct { const test_filename = test_file.source.path.name.filename; const dir_path = test_file.source.path.name.dirWithTrailingSlash(); - var snapshot_file_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var snapshot_file_path_buf: bun.PathBuffer = undefined; var remain: []u8 = snapshot_file_path_buf[0..bun.MAX_PATH_BYTES]; bun.copy(u8, remain, dir_path); remain = remain[dir_path.len..]; @@ -218,7 +218,7 @@ pub const Snapshots = struct { const test_filename = test_file.source.path.name.filename; const dir_path = test_file.source.path.name.dirWithTrailingSlash(); - var snapshot_file_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var snapshot_file_path_buf: bun.PathBuffer = undefined; var remain: []u8 = snapshot_file_path_buf[0..bun.MAX_PATH_BYTES]; bun.copy(u8, remain, dir_path); remain = remain[dir_path.len..]; diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index 9789aadfda39e8..33383ba77fa996 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -1172,7 +1172,7 @@ pub const Blob = struct { comptime needs_open: bool, ) JSC.JSValue { const fd: bun.FileDescriptor = if (comptime !needs_open) pathlike.fd else brk: { - var file_path: [bun.MAX_PATH_BYTES]u8 = undefined; + var file_path: bun.PathBuffer = undefined; switch (bun.sys.open( pathlike.path.sliceZ(&file_path), // we deliberately don't use O_TRUNC here @@ -1255,7 +1255,7 @@ pub const Blob = struct { comptime needs_open: bool, ) JSC.JSValue { const fd: bun.FileDescriptor = if (comptime !needs_open) pathlike.fd else brk: { - var file_path: [bun.MAX_PATH_BYTES]u8 = undefined; + var file_path: bun.PathBuffer = undefined; switch (bun.sys.open( pathlike.path.sliceZ(&file_path), if (!Environment.isWindows) @@ -1736,7 +1736,7 @@ pub const Blob = struct { std.os.O.RDONLY | __opener_flags; pub inline fn getFdByOpening(this: *This, comptime Callback: OpenCallback) void { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; var path_string = if (@hasField(This, "file_store")) this.file_store.pathlike.path else @@ -1953,8 +1953,8 @@ pub const Blob = struct { } fn copyfile(this: *CopyFileWindows) void { - var pathbuf1: [bun.MAX_PATH_BYTES]u8 = undefined; - var pathbuf2: [bun.MAX_PATH_BYTES]u8 = undefined; + var pathbuf1: bun.PathBuffer = undefined; + var pathbuf2: bun.PathBuffer = undefined; var destination_file_store = &this.destination_file_store.data.file; var source_file_store = &this.source_file_store.data.file; @@ -2290,7 +2290,7 @@ pub const Blob = struct { const open_source_flags = O.CLOEXEC | O.RDONLY; pub fn doOpenFile(this: *CopyFile, comptime which: IOWhich) !void { - var path_buf1: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf1: bun.PathBuffer = undefined; // open source file first // if it fails, we don't want the extra destination file hanging out if (which == .both or which == .source) { @@ -2496,8 +2496,8 @@ pub const Blob = struct { } pub fn doClonefile(this: *CopyFile) anyerror!void { - var source_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - var dest_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var source_buf: bun.PathBuffer = undefined; + var dest_buf: bun.PathBuffer = undefined; while (true) { const dest = this.destination_file_store.pathlike.path.sliceZ( @@ -2552,7 +2552,7 @@ pub const Blob = struct { if (comptime Environment.isMac) { if (this.offset == 0 and this.source_file_store.pathlike == .path and this.destination_file_store.pathlike == .path) { do_clonefile: { - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; // stat the output file, make sure it: // 1. Exists @@ -2983,7 +2983,7 @@ pub const Blob = struct { const pathlike = store.data.file.pathlike; const vm = globalThis.bunVM(); const fd: bun.FileDescriptor = if (pathlike == .fd) pathlike.fd else brk: { - var file_path: [bun.MAX_PATH_BYTES]u8 = undefined; + var file_path: bun.PathBuffer = undefined; switch (bun.sys.open( pathlike.path.sliceZ(&file_path), std.os.O.WRONLY | std.os.O.CREAT | std.os.O.NONBLOCK, @@ -3363,7 +3363,7 @@ pub const Blob = struct { /// resolve file stat like size, last_modified fn resolveFileStat(store: *Store) void { if (store.data.file.pathlike == .path) { - var buffer: [bun.MAX_PATH_BYTES]u8 = undefined; + var buffer: bun.PathBuffer = undefined; switch (bun.sys.stat(store.data.file.pathlike.path.sliceZ(&buffer))) { .result => |stat| { store.data.file.max_size = if (bun.isRegularFile(stat.mode) or stat.size > 0) diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index 23d1e08a8475b1..3f81e5017e4043 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -2271,9 +2271,9 @@ pub const Fetch = struct { if (is_file_url) { defer allocator.free(url_proxy_buffer); defer unix_socket_path.deinit(); - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; const PercentEncoding = @import("../../url.zig").PercentEncoding; - var path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf2: bun.PathBuffer = undefined; var stream = std.io.fixedBufferStream(&path_buf2); var url_path_decoded = path_buf2[0 .. PercentEncoding.decode( @TypeOf(&stream.writer()), @@ -2299,7 +2299,7 @@ pub const Fetch = struct { break :brk url_path_decoded; } - var cwd_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var cwd_buf: bun.PathBuffer = undefined; const cwd = if (Environment.isWindows) (std.os.getcwd(&cwd_buf) catch |err| { globalThis.throwError(err, "Failed to resolve file url"); return .zero; diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig index 21f8e15f4a30b9..4d0d7911cbbd1b 100644 --- a/src/bun.js/webcore/streams.zig +++ b/src/bun.js/webcore/streams.zig @@ -3482,7 +3482,7 @@ pub const FileReader = struct { pub fn openFileBlob(file: *Blob.FileStore) JSC.Maybe(OpenedFileBlob) { var this = OpenedFileBlob{ .fd = bun.invalid_fd }; - var file_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var file_buf: bun.PathBuffer = undefined; var is_nonblocking_tty = false; const fd = if (file.pathlike == .fd) diff --git a/src/bundler.zig b/src/bundler.zig index d15e7913a11f8b..c7177379ebc030 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -395,7 +395,7 @@ pub const Bundler = struct { pub fn resolveEntryPoint(bundler: *Bundler, entry_point: string) !_resolver.Result { return _resolveEntryPoint(bundler, entry_point) catch |err| { - var cache_bust_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var cache_bust_buf: bun.PathBuffer = undefined; // Bust directory cache and try again const buster_name = name: { @@ -1658,9 +1658,9 @@ pub const Bundler = struct { } // This is public so it can be used by the HTTP handler when matching against public dir. - pub threadlocal var tmp_buildfile_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var tmp_buildfile_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var tmp_buildfile_buf3: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var tmp_buildfile_buf: bun.PathBuffer = undefined; + threadlocal var tmp_buildfile_buf2: bun.PathBuffer = undefined; + threadlocal var tmp_buildfile_buf3: bun.PathBuffer = undefined; // We try to be mostly stateless when serving // This means we need a slightly different resolver setup diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index 80a03b4679caf5..b350fe8fede912 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -2536,7 +2536,7 @@ pub const ParseTask = struct { }; }; - threadlocal var override_file_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + threadlocal var override_file_path_buf: bun.PathBuffer = undefined; fn getEmptyAST(log: *Logger.Log, bundler: *Bundler, opts: js_parser.Parser.Options, allocator: std.mem.Allocator, source: Logger.Source, comptime RootType: type) !JSAst { const root = Expr.init(RootType, RootType{}, Logger.Loc.Empty); @@ -4222,7 +4222,7 @@ const LinkerContext = struct { }; defer dir.close(); - var real_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var real_path_buf: bun.PathBuffer = undefined; chunk.template.placeholder.dir = try resolve_path.relativeAlloc(this.allocator, this.resolver.opts.root_dir, try bun.getFdPath(bun.toFD(dir.fd), &real_path_buf)); } @@ -9053,7 +9053,7 @@ const LinkerContext = struct { // resolve any /./ and /../ occurrences // use resolvePosix since we asserted above all seps are '/' if (Environment.isWindows and std.mem.indexOf(u8, rel_path, "/./") != null) { - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const rel_path_fixed = c.allocator.dupe(u8, bun.path.normalizeBuf(rel_path, &buf, .posix)) catch bun.outOfMemory(); chunk.final_rel_path = rel_path_fixed; continue; @@ -9448,7 +9448,7 @@ const LinkerContext = struct { const code_with_inline_source_map_allocator = max_heap_allocator_inline_source_map.init(bun.default_allocator); - var pathbuf: [bun.MAX_PATH_BYTES]u8 = undefined; + var pathbuf: bun.PathBuffer = undefined; for (chunks) |*chunk| { const trace2 = tracer(@src(), "writeChunkToDisk"); diff --git a/src/bundler/entry_points.zig b/src/bundler/entry_points.zig index 654a7926fb6e6d..1237f02fa4578e 100644 --- a/src/bundler/entry_points.zig +++ b/src/bundler/entry_points.zig @@ -9,7 +9,7 @@ const strings = bun.strings; pub const FallbackEntryPoint = struct { code_buffer: [8192]u8 = undefined, - path_buffer: [bun.MAX_PATH_BYTES]u8 = undefined, + path_buffer: bun.PathBuffer = undefined, source: logger.Source = undefined, built_code: string = "", @@ -75,7 +75,7 @@ pub const FallbackEntryPoint = struct { pub const ClientEntryPoint = struct { code_buffer: [8192]u8 = undefined, - path_buffer: [bun.MAX_PATH_BYTES]u8 = undefined, + path_buffer: bun.PathBuffer = undefined, source: logger.Source = undefined, pub fn isEntryPointPath(extname: string) bool { diff --git a/src/cli.zig b/src/cli.zig index 4d7cb3cdc5442a..3c599c97746084 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -289,7 +289,7 @@ pub const Arguments = struct { try Bunfig.parse(allocator, logger.Source.initPathString(bun.asByteSlice(config_path), contents), ctx, cmd); } - fn getHomeConfigPath(buf: *[bun.MAX_PATH_BYTES]u8) ?[:0]const u8 { + fn getHomeConfigPath(buf: *bun.PathBuffer) ?[:0]const u8 { if (bun.getenvZ("XDG_CONFIG_HOME") orelse bun.getenvZ(bun.DotEnv.home_env)) |data_dir| { var paths = [_]string{".bunfig.toml"}; return resolve_path.joinAbsStringBufZ(data_dir, buf, &paths, .auto); @@ -298,7 +298,7 @@ pub const Arguments = struct { return null; } pub fn loadConfig(allocator: std.mem.Allocator, user_config_path_: ?string, ctx: Command.Context, comptime cmd: Command.Tag) !void { - var config_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var config_buf: bun.PathBuffer = undefined; if (comptime cmd.readGlobalConfig()) { if (!ctx.has_loaded_global_config) { ctx.has_loaded_global_config = true; @@ -335,7 +335,7 @@ pub const Arguments = struct { config_path = config_buf[0..config_path_.len :0]; } else { if (ctx.args.absolute_working_dir == null) { - var secondbuf: [bun.MAX_PATH_BYTES]u8 = undefined; + var secondbuf: bun.PathBuffer = undefined; const cwd = bun.getcwd(&secondbuf) catch return; ctx.args.absolute_working_dir = try allocator.dupe(u8, cwd); @@ -409,7 +409,7 @@ pub const Arguments = struct { var cwd: []u8 = undefined; if (args.option("--cwd")) |cwd_arg| { cwd = brk: { - var outbuf: [bun.MAX_PATH_BYTES]u8 = undefined; + var outbuf: bun.PathBuffer = undefined; const out = bun.path.joinAbs(try bun.getcwd(&outbuf), .loose, cwd_arg); bun.sys.chdir(out).unwrap() catch |err| { Output.err(err, "Could not change directory to \"{s}\"\n", .{cwd_arg}); @@ -1099,7 +1099,7 @@ pub var pretend_to_be_node = false; pub var is_bunx_exe = false; pub const Command = struct { - var script_name_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var script_name_buf: bun.PathBuffer = undefined; pub const DebugOptions = struct { dump_environment_variables: bool = false, @@ -1946,7 +1946,7 @@ pub const Command = struct { break :brk bun.openFileZ(file_pathZ, .{ .mode = .read_only }); } else { - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; const cwd = bun.getcwd(&path_buf) catch return false; path_buf[cwd.len] = std.fs.path.sep; var parts = [_]string{script_name_to_search}; diff --git a/src/cli/build_command.zig b/src/cli/build_command.zig index 60ddfd6da16983..288ab6c3a84e4e 100644 --- a/src/cli/build_command.zig +++ b/src/cli/build_command.zig @@ -184,7 +184,7 @@ pub const BuildCommand = struct { this_bundler.options.output_dir = ctx.bundler_options.outdir; this_bundler.resolver.opts.output_dir = ctx.bundler_options.outdir; - var src_root_dir_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var src_root_dir_buf: bun.PathBuffer = undefined; const src_root_dir: string = brk1: { const path = brk2: { if (ctx.bundler_options.root_dir.len > 0) { @@ -433,7 +433,7 @@ pub const BuildCommand = struct { // So don't do that unless we actually need to. // const do_we_need_to_close = !FeatureFlags.store_file_descriptors or (@intCast(usize, root_dir.fd) + open_file_limit) < output_files.len; - var filepath_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var filepath_buf: bun.PathBuffer = undefined; filepath_buf[0] = '.'; filepath_buf[1] = '/'; @@ -460,7 +460,7 @@ pub const BuildCommand = struct { } } const JSC = bun.JSC; - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; switch (JSC.Node.NodeFS.writeFileWithPathBuffer( &path_buf, JSC.Node.Arguments.WriteFile{ diff --git a/src/cli/bunx_command.zig b/src/cli/bunx_command.zig index 9803cabf0d8c64..3871b2aa5b4475 100644 --- a/src/cli/bunx_command.zig +++ b/src/cli/bunx_command.zig @@ -16,7 +16,7 @@ const Run = @import("./run_command.zig").RunCommand; const debug = Output.scoped(.bunx, false); pub const BunxCommand = struct { - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; /// Adds `create-` to the string, but also handles scoped packages correctly. /// Always clones the string in the process. @@ -135,13 +135,13 @@ pub const BunxCommand = struct { } fn getBinNameFromProjectDirectory(bundler: *bun.Bundler, dir_fd: bun.FileDescriptor, package_name: []const u8) ![]const u8 { - var subpath: [bun.MAX_PATH_BYTES]u8 = undefined; + var subpath: bun.PathBuffer = undefined; const subpath_z = std.fmt.bufPrintZ(&subpath, bun.pathLiteral("node_modules/{s}/package.json"), .{package_name}) catch unreachable; return try getBinNameFromSubpath(bundler, dir_fd, subpath_z); } fn getBinNameFromTempDirectory(bundler: *bun.Bundler, tempdir_name: []const u8, package_name: []const u8, with_stale_check: bool) ![]const u8 { - var subpath: [bun.MAX_PATH_BYTES]u8 = undefined; + var subpath: bun.PathBuffer = undefined; if (with_stale_check) { const subpath_z = std.fmt.bufPrintZ( &subpath, diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig index fe128cee438dbf..76b97fb4cfe289 100644 --- a/src/cli/create_command.zig +++ b/src/cli/create_command.zig @@ -41,7 +41,7 @@ const clap = bun.clap; const Lock = @import("../lock.zig").Lock; const Headers = bun.http.Headers; const CopyFile = @import("../copy_file.zig"); -var bun_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; +var bun_path_buf: bun.PathBuffer = undefined; const Futex = @import("../futex.zig"); const ComptimeStringMap = @import("../comptime_string_map.zig").ComptimeStringMap; @@ -235,7 +235,7 @@ const CreateOptions = struct { }; const BUN_CREATE_DIR = ".bun-create"; -var home_dir_buf: [bun.MAX_PATH_BYTES]u8 = undefined; +var home_dir_buf: bun.PathBuffer = undefined; pub const CreateCommand = struct { pub fn exec(ctx: Command.Context, example_tag: Example.Tag, template: []const u8) !void { @setCold(true); diff --git a/src/cli/exec_command.zig b/src/cli/exec_command.zig index d15e254873b6ea..de51c9c20de3fd 100644 --- a/src/cli/exec_command.zig +++ b/src/cli/exec_command.zig @@ -24,7 +24,7 @@ pub const ExecCommand = struct { ); try bundle.runEnvLoader(false); const mini = bun.JSC.MiniEventLoop.initGlobal(bundle.env); - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const cwd = switch (bun.sys.getcwd(&buf)) { .result => |p| p, diff --git a/src/cli/install_completions_command.zig b/src/cli/install_completions_command.zig index 51b819242417c6..054b5b1111bd53 100644 --- a/src/cli/install_completions_command.zig +++ b/src/cli/install_completions_command.zig @@ -47,7 +47,7 @@ pub const InstallCompletionsCommand = struct { const bunx_name = if (Environment.isDebug) "bunx-debug" else "bunx"; fn installBunxSymlinkPosix(cwd: []const u8) !void { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; // don't install it if it's already there if (bun.which(&buf, bun.getenvZ("PATH") orelse cwd, cwd, bunx_name) != null) @@ -55,7 +55,7 @@ pub const InstallCompletionsCommand = struct { // first try installing the symlink into the same directory as the bun executable const exe = try bun.selfExePath(); - var target_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var target_buf: bun.PathBuffer = undefined; var target = std.fmt.bufPrint(&target_buf, "{s}/" ++ bunx_name, .{std.fs.path.dirname(exe).?}) catch unreachable; std.os.symlink(exe, target) catch { outer: { @@ -168,7 +168,7 @@ pub const InstallCompletionsCommand = struct { // Fail silently on auto-update. const fail_exit_code: u8 = if (bun.getenvZ("IS_BUN_AUTO_UPDATE") == null) 1 else 0; - var cwd_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var cwd_buf: bun.PathBuffer = undefined; var stdout = std.io.getStdOut(); @@ -467,9 +467,9 @@ pub const InstallCompletionsCommand = struct { // Check if they need to load the zsh completions file into their .zshrc if (shell == .zsh) { - var completions_absolute_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var completions_absolute_path_buf: bun.PathBuffer = undefined; const completions_path = bun.getFdPath(output_file.handle, &completions_absolute_path_buf) catch unreachable; - var zshrc_filepath: [bun.MAX_PATH_BYTES]u8 = undefined; + var zshrc_filepath: bun.PathBuffer = undefined; const needs_to_tell_them_to_add_completions_file = brk: { var dot_zshrc: std.fs.File = zshrc: { first: { diff --git a/src/cli/package_manager_command.zig b/src/cli/package_manager_command.zig index 68848bf83371e6..fb02fc5431f62e 100644 --- a/src/cli/package_manager_command.zig +++ b/src/cli/package_manager_command.zig @@ -57,7 +57,7 @@ pub const PackageManagerCommand = struct { pub fn printHash(ctx: Command.Context, lockfile_: []const u8) !void { @setCold(true); - var lockfile_buffer: [bun.MAX_PATH_BYTES]u8 = undefined; + var lockfile_buffer: bun.PathBuffer = undefined; @memcpy(lockfile_buffer[0..lockfile_.len], lockfile_); lockfile_buffer[lockfile_.len] = 0; const lockfile = lockfile_buffer[0..lockfile_.len :0]; @@ -123,7 +123,7 @@ pub const PackageManagerCommand = struct { var pm = PackageManager.init(ctx, PackageManager.Subcommand.pm) catch |err| { if (err == error.MissingPackageJSON) { - var cwd_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var cwd_buf: bun.PathBuffer = undefined; if (bun.getcwd(&cwd_buf)) |cwd| { Output.errGeneric("No package.json was found for directory \"{s}\"", .{cwd}); } else |_| { @@ -193,7 +193,7 @@ pub const PackageManagerCommand = struct { _ = try pm.lockfile.hasMetaHashChanged(true, pm.lockfile.packages.len); Global.exit(0); } else if (strings.eqlComptime(subcommand, "cache")) { - var dir: [bun.MAX_PATH_BYTES]u8 = undefined; + var dir: bun.PathBuffer = undefined; var fd = pm.getCacheDirectory(); const outpath = bun.getFdPath(fd.fd, &dir) catch |err| { Output.prettyErrorln("{s} getting cache directory", .{@errorName(err)}); @@ -300,7 +300,7 @@ pub const PackageManagerCommand = struct { if (strings.leftHasAnyInRight(args, &.{ "-A", "-a", "--all" })) { try printNodeModulesFolderStructure(&first_directory, null, 0, &directories, lockfile, more_packages); } else { - var cwd_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var cwd_buf: bun.PathBuffer = undefined; const path = bun.getcwd(&cwd_buf) catch { Output.prettyErrorln("error: Could not get current working directory", .{}); Global.exit(1); @@ -428,7 +428,7 @@ fn printNodeModulesFolderStructure( Output.prettyln("{s}@{s}", .{ path, directory_version }); } } else { - var cwd_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var cwd_buf: bun.PathBuffer = undefined; const path = bun.getcwd(&cwd_buf) catch { Output.prettyErrorln("error: Could not get current working directory", .{}); Global.exit(1); diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index 7127f4c1580e11..213c1764c8c7f9 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -37,8 +37,8 @@ const bundler = bun.bundler; const DotEnv = @import("../env_loader.zig"); const which = @import("../which.zig").which; const Run = @import("../bun_js.zig").Run; -var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; -var path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; +var path_buf: bun.PathBuffer = undefined; +var path_buf2: bun.PathBuffer = undefined; const NpmArgs = struct { // https://github.com/npm/rfcs/blob/main/implemented/0021-reduce-lifecycle-script-environment.md#detailed-explanation pub const package_name: string = "npm_package_name"; @@ -103,7 +103,7 @@ pub const RunCommand = struct { /// Cached to only run once pub fn findShell(PATH: string, cwd: string) ?stringZ { const bufs = struct { - pub var shell_buf_once: [bun.MAX_PATH_BYTES]u8 = undefined; + pub var shell_buf_once: bun.PathBuffer = undefined; pub var found_shell: [:0]const u8 = ""; }; if (bufs.found_shell.len > 0) { diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig index 797c0c1c4ca189..7f9d7b53e5956d 100644 --- a/src/cli/test_command.zig +++ b/src/cli/test_command.zig @@ -31,8 +31,8 @@ const Command = @import("../cli.zig").Command; const DotEnv = @import("../env_loader.zig"); const which = @import("../which.zig").which; const Run = @import("../bun_js.zig").Run; -var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; -var path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; +var path_buf: bun.PathBuffer = undefined; +var path_buf2: bun.PathBuffer = undefined; const PathString = bun.PathString; const is_bindgen = std.meta.globalOption("bindgen", bool) orelse false; const HTTPThread = bun.http.HTTPThread; @@ -376,8 +376,8 @@ const Scanner = struct { dirs_to_scan: Fifo, results: *std.ArrayList(bun.PathString), fs: *FileSystem, - open_dir_buf: [bun.MAX_PATH_BYTES]u8 = undefined, - scan_dir_buf: [bun.MAX_PATH_BYTES]u8 = undefined, + open_dir_buf: bun.PathBuffer = undefined, + scan_dir_buf: bun.PathBuffer = undefined, options: *options.BundleOptions, has_iterated: bool = false, search_count: usize = 0, diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig index 6b312a39995bc5..18935cf7e0f563 100644 --- a/src/cli/upgrade_command.zig +++ b/src/cli/upgrade_command.zig @@ -164,10 +164,10 @@ pub const UpgradeCheckerThread = struct { pub const UpgradeCommand = struct { pub const timeout: u32 = 30000; const default_github_headers: string = "Acceptapplication/vnd.github.v3+json"; - var github_repository_url_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - var current_executable_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - var unzip_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - var tmpdir_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var github_repository_url_buf: bun.PathBuffer = undefined; + var current_executable_buf: bun.PathBuffer = undefined; + var unzip_path_buf: bun.PathBuffer = undefined; + var tmpdir_path_buf: bun.PathBuffer = undefined; pub fn getLatestVersion( allocator: std.mem.Allocator, diff --git a/src/env_loader.zig b/src/env_loader.zig index 9f35a35ec07299..c07499b0335759 100644 --- a/src/env_loader.zig +++ b/src/env_loader.zig @@ -193,7 +193,7 @@ pub const Loader = struct { // if they have ccache installed, put it in env variable `CMAKE_CXX_COMPILER_LAUNCHER` so // cmake can use it to hopefully speed things up - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const ccache_path = bun.which( &buf, this.get("PATH") orelse return, diff --git a/src/fs.zig b/src/fs.zig index edf9b061e645cb..1b19a4ed44f3f6 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -39,7 +39,7 @@ pub const FileSystem = struct { top_level_dir: string = if (Environment.isWindows) "C:\\" else "/", // used on subsequent updates - top_level_dir_buf: [bun.MAX_PATH_BYTES]u8 = undefined, + top_level_dir_buf: bun.PathBuffer = undefined, fs: Implementation, @@ -67,7 +67,7 @@ pub const FileSystem = struct { } pub fn getFdPath(this: *const FileSystem, fd: FileDescriptor) ![]const u8 { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const dir = try bun.getFdPath(fd, &buf); return try this.dirname_store.append([]u8, dir); } @@ -257,7 +257,7 @@ pub const FileSystem = struct { pub fn get(entry: *const DirEntry, _query: string) ?Entry.Lookup { if (_query.len == 0 or _query.len > bun.MAX_PATH_BYTES) return null; - var scratch_lookup_buffer: [bun.MAX_PATH_BYTES]u8 = undefined; + var scratch_lookup_buffer: bun.PathBuffer = undefined; const query = strings.copyLowercaseIfNeeded(_query, &scratch_lookup_buffer); const result = entry.data.get(query) orelse return null; @@ -554,7 +554,7 @@ pub const FileSystem = struct { } if (bun.getenvZ("USERPROFILE")) |profile| { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; var parts = [_]string{"AppData\\Local\\Temp"}; const out = bun.path.joinAbsStringBuf(profile, &buf, &parts, .loose); break :brk bun.default_allocator.dupe(u8, out) catch bun.outOfMemory(); @@ -720,7 +720,7 @@ pub const FileSystem = struct { const flags = std.os.O.CREAT | std.os.O.WRONLY | std.os.O.CLOEXEC; this.fd = try bun.sys.openat(bun.toFD(tmpdir_.fd), name, flags, 0).unwrap(); - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const existing_path = try bun.getFdPath(this.fd, &buf); this.existing_path = try bun.default_allocator.dupe(u8, existing_path); } @@ -1262,7 +1262,7 @@ pub const FileSystem = struct { existing_fd: StoredFileDescriptorType, store_fd: bool, ) !Entry.Cache { - var outpath: [bun.MAX_PATH_BYTES]u8 = undefined; + var outpath: bun.PathBuffer = undefined; const stat = try C.lstat_absolute(absolute_path); const is_symlink = stat.kind == std.fs.File.Kind.SymLink; diff --git a/src/glob.zig b/src/glob.zig index c8a14ab895fb0e..db0ef0dc3f71ec 100644 --- a/src/glob.zig +++ b/src/glob.zig @@ -127,7 +127,7 @@ fn dummyFilterFalse(val: []const u8) bool { pub fn statatWindows(fd: bun.FileDescriptor, path: [:0]const u8) Maybe(bun.Stat) { if (comptime !bun.Environment.isWindows) @compileError("oi don't use this"); - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const dir = switch (Syscall.getFdPath(fd, &buf)) { .err => |e| return .{ .err = e }, .result => |s| s, @@ -195,7 +195,7 @@ pub const SyscallAccessor = struct { return Syscall.close(handle.value); } - pub fn getcwd(path_buf: *[bun.MAX_PATH_BYTES]u8) Maybe([]const u8) { + pub fn getcwd(path_buf: *bun.PathBuffer) Maybe([]const u8) { return Syscall.getcwd(path_buf); } }; @@ -312,7 +312,7 @@ pub const DirEntryAccessor = struct { return null; } - pub fn getcwd(path_buf: *[bun.MAX_PATH_BYTES]u8) Maybe([]const u8) { + pub fn getcwd(path_buf: *bun.PathBuffer) Maybe([]const u8) { @memcpy(path_buf, bun.fs.FileSystem.instance.fs.cwd); } }; @@ -423,7 +423,7 @@ pub fn GlobWalker_( const Directory = struct { fd: Accessor.Handle, iter: Accessor.DirIter, - path: [bun.MAX_PATH_BYTES]u8, + path: bun.PathBuffer, dir_path: [:0]const u8, component_idx: u32, @@ -511,7 +511,7 @@ pub fn GlobWalker_( ); }; - var path_buf: *[bun.MAX_PATH_BYTES]u8 = &this.walker.pathBuf; + var path_buf: *bun.PathBuffer = &this.walker.pathBuf; const root_path = root_work_item.path; @memcpy(path_buf[0..root_path.len], root_path[0..root_path.len]); path_buf[root_path.len] = 0; @@ -730,7 +730,7 @@ pub fn GlobWalker_( continue; }, .symlink => { - var scratch_path_buf: *[bun.MAX_PATH_BYTES]u8 = &this.walker.pathBuf; + var scratch_path_buf: *bun.PathBuffer = &this.walker.pathBuf; @memcpy(scratch_path_buf[0..work_item.path.len], work_item.path); scratch_path_buf[work_item.path.len] = 0; var symlink_full_path_z: [:0]u8 = scratch_path_buf[0..work_item.path.len :0]; @@ -1150,7 +1150,7 @@ pub fn GlobWalker_( this: *GlobWalker, idx: u32, dir_path: *[:0]u8, - path_buf: *[bun.MAX_PATH_BYTES]u8, + path_buf: *bun.PathBuffer, encountered_dot_dot: *bool, ) u32 { var component_idx = idx; @@ -1213,7 +1213,7 @@ pub fn GlobWalker_( this: *GlobWalker, work_item_idx: u32, dir_path: *[:0]u8, - scratch_path_buf: *[bun.MAX_PATH_BYTES]u8, + scratch_path_buf: *bun.PathBuffer, encountered_dot_dot: *bool, ) u32 { var component_idx = work_item_idx; diff --git a/src/install/bin.zig b/src/install/bin.zig index 0a24b2016d6253..15816285d40522 100644 --- a/src/install/bin.zig +++ b/src/install/bin.zig @@ -185,7 +185,7 @@ pub const Bin = extern struct { dir_iterator: ?std.fs.Dir.Iterator = null, package_name: String, package_installed_node_modules: std.fs.Dir = bun.invalid_fd.asDir(), - buf: [bun.MAX_PATH_BYTES]u8 = undefined, + buf: bun.PathBuffer = undefined, string_buffer: []const u8, extern_string_buf: []const ExternalString, @@ -474,8 +474,8 @@ pub const Bin = extern struct { // That way, if you move your node_modules folder around, the symlinks in .bin still work // If we used absolute paths for the symlinks, you'd end up with broken symlinks pub fn link(this: *Linker, link_global: bool) void { - var target_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - var dest_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var target_buf: bun.PathBuffer = undefined; + var dest_buf: bun.PathBuffer = undefined; var from_remain: []u8 = &target_buf; var remain: []u8 = &dest_buf; @@ -698,8 +698,8 @@ pub const Bin = extern struct { } pub fn unlink(this: *Linker, link_global: bool) void { - var target_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - var dest_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var target_buf: bun.PathBuffer = undefined; + var dest_buf: bun.PathBuffer = undefined; var from_remain: []u8 = &target_buf; var remain: []u8 = &dest_buf; diff --git a/src/install/install.zig b/src/install/install.zig index 614ecb1ce2b0ae..5bd67da7b28220 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -1188,7 +1188,7 @@ pub const PackageInstall = struct { walker: *Walker, ) !u32 { var real_file_count: u32 = 0; - var stackpath: [bun.MAX_PATH_BYTES]u8 = undefined; + var stackpath: bun.PathBuffer = undefined; while (try walker.next()) |entry| { switch (entry.kind) { .directory => { @@ -2065,7 +2065,7 @@ pub const PackageInstall = struct { var dest_buf: bun.PathBuffer = undefined; // cache_dir_subpath in here is actually the full path to the symlink pointing to the linked package const symlinked_path = this.cache_dir_subpath; - var to_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var to_buf: bun.PathBuffer = undefined; const to_path = this.cache_dir.realpath(symlinked_path, &to_buf) catch |err| return Result{ .fail = .{ .err = err, @@ -2663,7 +2663,7 @@ pub const PackageManager = struct { this.env.loadCCachePath(this_bundler.fs); { - var node_path: [bun.MAX_PATH_BYTES]u8 = undefined; + var node_path: bun.PathBuffer = undefined; if (this.env.getNodePath(this_bundler.fs, &node_path)) |node_pathZ| { _ = try this.env.loadNodeJSConfig(this_bundler.fs, bun.default_allocator.dupe(u8, node_pathZ) catch bun.outOfMemory()); } else brk: { @@ -2892,7 +2892,7 @@ pub const PackageManager = struct { var global_dir = try Options.openGlobalDir(this.options.explicit_global_directory); this.global_dir = global_dir; this.global_link_dir = try global_dir.makeOpenPath("node_modules", .{}); - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const _path = try bun.getFdPath(this.global_link_dir.?.fd, &buf); this.global_link_dir_path = try Fs.FileSystem.DirnameStore.instance.append([]const u8, _path); break :brk this.global_link_dir.?; @@ -3035,7 +3035,7 @@ pub const PackageManager = struct { } } - var cached_package_folder_name_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var cached_package_folder_name_buf: bun.PathBuffer = undefined; pub inline fn getCacheDirectory(this: *PackageManager) std.fs.Dir { return this.cache_directory_ orelse brk: { @@ -3102,7 +3102,7 @@ pub const PackageManager = struct { Global.crash(); }; }; - var tmpbuf: [bun.MAX_PATH_BYTES]u8 = undefined; + var tmpbuf: bun.PathBuffer = undefined; const tmpname = Fs.FileSystem.instance.tmpname("hm", &tmpbuf, bun.fastRandom()) catch unreachable; var timer: std.time.Timer = if (this.options.log_level != .silent) std.time.Timer.start() catch unreachable else undefined; brk: while (true) { @@ -3157,7 +3157,7 @@ pub const PackageManager = struct { if (this.options.log_level != .silent) { const elapsed = timer.read(); if (elapsed > std.time.ns_per_ms * 100) { - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; const cache_dir_path = bun.getFdPath(cache_directory.fd, &path_buf) catch "it"; Output.prettyErrorln( "warn: Slow filesystem detected. If {s} is a network drive, consider setting $BUN_INSTALL_CACHE_DIR to a local folder.", @@ -3173,7 +3173,7 @@ pub const PackageManager = struct { if (this.node_gyp_tempdir_name.len > 0) return; const tempdir = this.getTemporaryDirectory(); - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; const node_gyp_tempdir_name = bun.span(try Fs.FileSystem.instance.tmpname("node-gyp", &path_buf, 12345)); // used later for adding to path for scripts @@ -3439,11 +3439,11 @@ pub const PackageManager = struct { pub fn pathForCachedNPMPath( this: *PackageManager, - buf: *[bun.MAX_PATH_BYTES]u8, + buf: *bun.PathBuffer, package_name: []const u8, npm: Semver.Version, ) ![]u8 { - var package_name_version_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var package_name_version_buf: bun.PathBuffer = undefined; const subpath = std.fmt.bufPrintZ( &package_name_version_buf, @@ -3468,7 +3468,7 @@ pub const PackageManager = struct { this: *PackageManager, package_id: PackageID, resolution: Resolution, - buf: *[bun.MAX_PATH_BYTES]u8, + buf: *bun.PathBuffer, ) ![]u8 { // const folder_name = this.cachedNPMPackageFolderName(name, version); switch (resolution.tag) { @@ -3545,7 +3545,7 @@ pub const PackageManager = struct { ); for (installed_versions.items) |installed_version| { if (version.value.npm.version.satisfies(installed_version, this.lockfile.buffers.string_bytes.items, tags_buf.items)) { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const npm_package_path = this.pathForCachedNPMPath(&buf, package_name, installed_version) catch |err| { Output.debug("error getting path for cached npm path: {s}", .{bun.span(@errorName(err))}); return null; @@ -6087,7 +6087,7 @@ pub const PackageManager = struct { } if (bun.getenvZ("BUN_INSTALL")) |home_dir| { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; var parts = [_]string{ "install", "global" }; const path = Path.joinAbsStringBuf(home_dir, &buf, &parts, .auto); return try std.fs.cwd().makeOpenPath(path, .{}); @@ -6095,14 +6095,14 @@ pub const PackageManager = struct { if (!Environment.isWindows) { if (bun.getenvZ("XDG_CACHE_HOME") orelse bun.getenvZ("HOME")) |home_dir| { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; var parts = [_]string{ ".bun", "install", "global" }; const path = Path.joinAbsStringBuf(home_dir, &buf, &parts, .auto); return try std.fs.cwd().makeOpenPath(path, .{}); } } else { if (bun.getenvZ("USERPROFILE")) |home_dir| { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; var parts = [_]string{ ".bun", "install", "global" }; const path = Path.joinAbsStringBuf(home_dir, &buf, &parts, .auto); return try std.fs.cwd().makeOpenPath(path, .{}); @@ -6126,7 +6126,7 @@ pub const PackageManager = struct { } if (bun.getenvZ("BUN_INSTALL")) |home_dir| { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; var parts = [_]string{ "bin", }; @@ -6135,7 +6135,7 @@ pub const PackageManager = struct { } if (bun.getenvZ("XDG_CACHE_HOME") orelse bun.getenvZ(bun.DotEnv.home_env)) |home_dir| { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; var parts = [_]string{ ".bun", "bin", @@ -7545,7 +7545,7 @@ pub const PackageManager = struct { ) -| std.time.s_per_day; if (root_dir.entries.hasComptimeQuery("bun.lockb")) { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; var parts = [_]string{ "./bun.lockb", }; @@ -8259,8 +8259,8 @@ pub const PackageManager = struct { // } if (args.option("--cwd")) |cwd_| { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; - var buf2: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; + var buf2: bun.PathBuffer = undefined; var final_path: [:0]u8 = undefined; if (cwd_.len > 0 and cwd_[0] == '.') { const cwd = try bun.getcwd(&buf); @@ -8766,7 +8766,7 @@ pub const PackageManager = struct { var cwd = std.fs.cwd(); // This is not exactly correct - var node_modules_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var node_modules_buf: bun.PathBuffer = undefined; bun.copy(u8, &node_modules_buf, "node_modules" ++ std.fs.path.sep_str); const offset_buf = node_modules_buf["node_modules/".len..]; const name_hashes = manager.lockfile.packages.items(.name_hash); @@ -8914,8 +8914,8 @@ pub const PackageManager = struct { resolutions: []Resolution, node: *Progress.Node, global_bin_dir: std.fs.Dir, - destination_dir_subpath_buf: [bun.MAX_PATH_BYTES]u8 = undefined, - folder_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined, + destination_dir_subpath_buf: bun.PathBuffer = undefined, + folder_path_buf: bun.PathBuffer = undefined, successfully_installed: Bitset, tree_iterator: *Lockfile.Tree.Iterator, command_ctx: Command.Context, @@ -10451,7 +10451,7 @@ pub const PackageManager = struct { pub fn setupGlobalDir(manager: *PackageManager, ctx: Command.Context) !void { manager.options.global_bin_dir = try Options.openGlobalBinDir(ctx.install); - var out_buffer: [bun.MAX_PATH_BYTES]u8 = undefined; + var out_buffer: bun.PathBuffer = undefined; const result = try bun.getFdPath(manager.options.global_bin_dir.fd, &out_buffer); out_buffer[result.len] = 0; const result_: [:0]u8 = out_buffer[0..result.len :0]; diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index ac11642369d8d1..f948c6bbc576d3 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -1085,8 +1085,8 @@ pub const Printer = struct { // We truncate longer than allowed paths. We should probably throw an error instead. const path = input_lockfile_path[0..@min(input_lockfile_path.len, bun.MAX_PATH_BYTES)]; - var lockfile_path_buf1: [bun.MAX_PATH_BYTES]u8 = undefined; - var lockfile_path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; + var lockfile_path_buf1: bun.PathBuffer = undefined; + var lockfile_path_buf2: bun.PathBuffer = undefined; var lockfile_path: stringZ = ""; diff --git a/src/install/migration.zig b/src/install/migration.zig index e66f8bb8310cfa..433becb0c44003 100644 --- a/src/install/migration.zig +++ b/src/install/migration.zig @@ -40,7 +40,7 @@ pub fn detectAndLoadOtherLockfile(this: *Lockfile, allocator: Allocator, log: *l const dirname = bun_lockfile_path[0 .. strings.lastIndexOfChar(bun_lockfile_path, '/') orelse 0]; // check for package-lock.json, yarn.lock, etc... // if it exists, do an in-memory migration - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; @memcpy(buf[0..dirname.len], dirname); npm: { diff --git a/src/install/repository.zig b/src/install/repository.zig index 769036a124f760..5465c39d27e61b 100644 --- a/src/install/repository.zig +++ b/src/install/repository.zig @@ -17,9 +17,9 @@ const strings = @import("../string_immutable.zig"); const GitSHA = String; const Path = bun.path; -threadlocal var final_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; -threadlocal var folder_name_buf: [bun.MAX_PATH_BYTES]u8 = undefined; -threadlocal var json_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; +threadlocal var final_path_buf: bun.PathBuffer = undefined; +threadlocal var folder_name_buf: bun.PathBuffer = undefined; +threadlocal var json_path_buf: bun.PathBuffer = undefined; pub const Repository = extern struct { owner: String = .{}, diff --git a/src/install/resolvers/folder_resolver.zig b/src/install/resolvers/folder_resolver.zig index afc7bfde7bc909..7cc29141ae7cef 100644 --- a/src/install/resolvers/folder_resolver.zig +++ b/src/install/resolvers/folder_resolver.zig @@ -117,7 +117,7 @@ pub const FolderResolution = union(Tag) { std.mem.trimRight(u8, normalize(non_normalized_path), std.fs.path.sep_str); if (strings.startsWithChar(normalized, '.')) { - var tempcat: [bun.MAX_PATH_BYTES]u8 = undefined; + var tempcat: bun.PathBuffer = undefined; bun.copy(u8, &tempcat, normalized); tempcat[normalized.len..][0.."/package.json".len].* = (std.fs.path.sep_str ++ "package.json").*; @@ -239,7 +239,7 @@ pub const FolderResolution = union(Tag) { }; pub fn getOrPut(global_or_relative: GlobalOrRelative, version: Dependency.Version, non_normalized_path: string, manager: *PackageManager) FolderResolution { - var joined: [bun.MAX_PATH_BYTES]u8 = undefined; + var joined: bun.PathBuffer = undefined; const paths = normalizePackageJSONPath(global_or_relative, &joined, non_normalized_path); const abs = paths.abs; const rel = paths.rel; @@ -256,7 +256,7 @@ pub const FolderResolution = union(Tag) { const package: Lockfile.Package = switch (global_or_relative) { .global => brk: { - var path: [bun.MAX_PATH_BYTES]u8 = undefined; + var path: bun.PathBuffer = undefined; std.mem.copyForwards(u8, &path, non_normalized_path); break :brk readPackageJSONFromDisk( manager, diff --git a/src/open.zig b/src/open.zig index ea2bd6d64ca688..27cfd0db02dae5 100644 --- a/src/open.zig +++ b/src/open.zig @@ -106,7 +106,7 @@ pub const Editor = enum(u8) { } const which = @import("./which.zig").which; - pub fn byPATH(env: *DotEnv.Loader, buf: *[bun.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) ?Editor { + pub fn byPATH(env: *DotEnv.Loader, buf: *bun.PathBuffer, cwd: string, out: *[]const u8) ?Editor { const PATH = env.get("PATH") orelse return null; inline for (default_preference_list) |editor| { @@ -121,7 +121,7 @@ pub const Editor = enum(u8) { return null; } - pub fn byPATHForEditor(env: *DotEnv.Loader, editor: Editor, buf: *[bun.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) bool { + pub fn byPATHForEditor(env: *DotEnv.Loader, editor: Editor, buf: *bun.PathBuffer, cwd: string, out: *[]const u8) bool { const PATH = env.get("PATH") orelse return false; if (bin_name.get(editor)) |path| { @@ -152,7 +152,7 @@ pub const Editor = enum(u8) { return false; } - pub fn byFallback(env: *DotEnv.Loader, buf: *[bun.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) ?Editor { + pub fn byFallback(env: *DotEnv.Loader, buf: *bun.PathBuffer, cwd: string, out: *[]const u8) ?Editor { inline for (default_preference_list) |editor| { if (byPATHForEditor(env, editor, buf, cwd, out)) { return editor; @@ -375,7 +375,7 @@ pub const EditorContext = struct { var opened = try tmpdir.openFile(basename, .{}); defer opened.close(); - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; try editor_.open( path, try bun.getFdPath(opened.handle, &path_buf), @@ -391,7 +391,7 @@ pub const EditorContext = struct { } } pub fn detectEditor(this: *EditorContext, env: *DotEnv.Loader) void { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; var out: string = ""; // first: choose from user preference diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig index b99ef46aeaecc6..c74338ecf7ab3e 100644 --- a/src/resolver/package_json.zig +++ b/src/resolver/package_json.zig @@ -1442,7 +1442,7 @@ pub const ESModule = struct { "%5C", }; - threadlocal var resolved_path_buf_percent: [bun.MAX_PATH_BYTES]u8 = undefined; + threadlocal var resolved_path_buf_percent: bun.PathBuffer = undefined; pub fn resolve(r: *const ESModule, package_url: string, subpath: string, exports: ExportsMap.Entry) Resolution { return finalize( r.resolveExports(package_url, subpath, exports), @@ -1656,8 +1656,8 @@ pub const ESModule = struct { }; } - threadlocal var resolve_target_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var resolve_target_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; + threadlocal var resolve_target_buf: bun.PathBuffer = undefined; + threadlocal var resolve_target_buf2: bun.PathBuffer = undefined; fn resolveTarget( r: *const ESModule, package_url: string, @@ -1962,8 +1962,8 @@ pub const ESModule = struct { } } - threadlocal var resolve_target_reverse_prefix_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var resolve_target_reverse_prefix_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; + threadlocal var resolve_target_reverse_prefix_buf: bun.PathBuffer = undefined; + threadlocal var resolve_target_reverse_prefix_buf2: bun.PathBuffer = undefined; fn resolveTargetReverse( r: *const ESModule, diff --git a/src/resolver/resolve_path.zig b/src/resolver/resolve_path.zig index f8ac881a8b08d5..fe3c8b77e436b1 100644 --- a/src/resolver/resolve_path.zig +++ b/src/resolver/resolve_path.zig @@ -9,7 +9,7 @@ const Fs = @import("../fs.zig"); threadlocal var parser_join_input_buffer: [4096]u8 = undefined; threadlocal var parser_buffer: [1024]u8 = undefined; -pub fn z(input: []const u8, output: *[bun.MAX_PATH_BYTES]u8) [:0]const u8 { +pub fn z(input: []const u8, output: *bun.PathBuffer) [:0]const u8 { if (input.len > bun.MAX_PATH_BYTES) { if (comptime bun.Environment.allow_assert) @panic("path too long"); return ""; diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index 520835e56d2139..b8627673ae1c09 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -86,34 +86,34 @@ const bufs = struct { // packages but we lack a decent module resolution benchmark right now. // Potentially revisit after https://github.com/oven-sh/bun/issues/2716 pub threadlocal var extension_path: [512]u8 = undefined; - pub threadlocal var tsconfig_match_full_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var tsconfig_match_full_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var tsconfig_match_full_buf3: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var tsconfig_match_full_buf: bun.PathBuffer = undefined; + pub threadlocal var tsconfig_match_full_buf2: bun.PathBuffer = undefined; + pub threadlocal var tsconfig_match_full_buf3: bun.PathBuffer = undefined; pub threadlocal var esm_subpath: [512]u8 = undefined; - pub threadlocal var esm_absolute_package_path: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var esm_absolute_package_path_joined: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var esm_absolute_package_path: bun.PathBuffer = undefined; + pub threadlocal var esm_absolute_package_path_joined: bun.PathBuffer = undefined; pub threadlocal var dir_entry_paths_to_resolve: [256]DirEntryResolveQueueItem = undefined; pub threadlocal var open_dirs: [256]std.fs.Dir = undefined; - pub threadlocal var resolve_without_remapping: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var index: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var dir_info_uncached_filename: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var node_bin_path: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var dir_info_uncached_path: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var tsconfig_base_url: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var relative_abs_path: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var load_as_file_or_directory_via_tsconfig_base_path: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var node_modules_check: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var field_abs_path: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var tsconfig_path_abs: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var check_browser_map: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var remap_path: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var load_as_file: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var remap_path_trailing_slash: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var path_in_global_disk_cache: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var abs_to_rel: [bun.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var node_modules_paths_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var resolve_without_remapping: bun.PathBuffer = undefined; + pub threadlocal var index: bun.PathBuffer = undefined; + pub threadlocal var dir_info_uncached_filename: bun.PathBuffer = undefined; + pub threadlocal var node_bin_path: bun.PathBuffer = undefined; + pub threadlocal var dir_info_uncached_path: bun.PathBuffer = undefined; + pub threadlocal var tsconfig_base_url: bun.PathBuffer = undefined; + pub threadlocal var relative_abs_path: bun.PathBuffer = undefined; + pub threadlocal var load_as_file_or_directory_via_tsconfig_base_path: bun.PathBuffer = undefined; + pub threadlocal var node_modules_check: bun.PathBuffer = undefined; + pub threadlocal var field_abs_path: bun.PathBuffer = undefined; + pub threadlocal var tsconfig_path_abs: bun.PathBuffer = undefined; + pub threadlocal var check_browser_map: bun.PathBuffer = undefined; + pub threadlocal var remap_path: bun.PathBuffer = undefined; + pub threadlocal var load_as_file: bun.PathBuffer = undefined; + pub threadlocal var remap_path_trailing_slash: bun.PathBuffer = undefined; + pub threadlocal var path_in_global_disk_cache: bun.PathBuffer = undefined; + pub threadlocal var abs_to_rel: bun.PathBuffer = undefined; + pub threadlocal var node_modules_paths_buf: bun.PathBuffer = undefined; pub inline fn bufs(comptime field: std.meta.DeclEnum(@This())) *@TypeOf(@field(@This(), @tagName(field))) { return &@field(@This(), @tagName(field)); @@ -736,7 +736,7 @@ pub const Resolver = struct { pkg.loadFrameworkWithPreference(pair, json, r.allocator, load_defines, preference); const dir = pkg.source.path.sourceDir(); - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; pair.framework.resolved_dir = pkg.source.path.sourceDir(); @@ -1069,7 +1069,7 @@ pub const Resolver = struct { } } else if (dir.abs_real_path.len > 0) { var parts = [_]string{ dir.abs_real_path, query.entry.base() }; - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; var out = r.fs.absBuf(&parts, &buf); diff --git a/src/runtime.zig b/src/runtime.zig index 6fa481be5a5a94..b92df47bac1d1c 100644 --- a/src/runtime.zig +++ b/src/runtime.zig @@ -34,7 +34,7 @@ fn embedDebugFallback(comptime msg: []const u8, comptime code: []const u8) []con pub const ErrorCSS = struct { pub inline fn sourceContent() string { if (comptime Environment.isDebug) { - var out_buffer: [bun.MAX_PATH_BYTES]u8 = undefined; + var out_buffer: bun.PathBuffer = undefined; const dirname = std.fs.selfExeDirPath(&out_buffer) catch unreachable; var paths = [_]string{ dirname, BUN_ROOT, content.error_css_path }; const file = std.fs.cwd().openFile( @@ -57,7 +57,7 @@ pub const ReactRefresh = @embedFile("./react-refresh.js"); pub const ErrorJS = struct { pub inline fn sourceContent() string { if (comptime Environment.isDebug) { - var out_buffer: [bun.MAX_PATH_BYTES]u8 = undefined; + var out_buffer: bun.PathBuffer = undefined; const dirname = std.fs.selfExeDirPath(&out_buffer) catch unreachable; var paths = [_]string{ dirname, BUN_ROOT, content.error_js_path }; const file = std.fs.cwd().openFile( diff --git a/src/shell/interpreter.zig b/src/shell/interpreter.zig index e45dbdbdf3672f..e05dfb2029bb7d 100644 --- a/src/shell/interpreter.zig +++ b/src/shell/interpreter.zig @@ -1108,7 +1108,7 @@ pub const Interpreter = struct { break :brk export_env; }; - var pathbuf: [bun.MAX_PATH_BYTES]u8 = undefined; + var pathbuf: bun.PathBuffer = undefined; const cwd = switch (Syscall.getcwd(&pathbuf)) { .result => |cwd| cwd.ptr[0..cwd.len :0], .err => |err| { @@ -4620,7 +4620,7 @@ pub const Interpreter = struct { return; } - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; const resolved = which(&path_buf, spawn_args.PATH, spawn_args.cwd, first_arg_real) orelse blk: { if (bun.strings.eqlComptime(first_arg_real, "bun") or bun.strings.eqlComptime(first_arg_real, "bun-debug")) blk2: { break :blk bun.selfExePath() catch break :blk2; @@ -6613,7 +6613,7 @@ pub const Interpreter = struct { pub fn onCreateDir(vtable: *@This(), dirpath: bun.OSPathSliceZ) void { if (!vtable.active) return; if (bun.Environment.isWindows) { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const str = bun.strings.fromWPath(&buf, dirpath[0..dirpath.len]); vtable.inner.created_directories.appendSlice(str) catch bun.outOfMemory(); vtable.inner.created_directories.append('\n') catch bun.outOfMemory(); @@ -6893,7 +6893,7 @@ pub const Interpreter = struct { } if (!this.bltn.stdout.needsIO()) { - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; const PATH = this.bltn.parentCmd().base.shell.export_env.get(EnvStr.initSlice("PATH")) orelse EnvStr.initSlice(""); var had_not_found = false; for (args) |arg_raw| { @@ -6933,7 +6933,7 @@ pub const Interpreter = struct { const arg_raw = multiargs.args_slice[multiargs.arg_idx]; const arg = arg_raw[0..std.mem.len(arg_raw)]; - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; const PATH = this.bltn.parentCmd().base.shell.export_env.get(EnvStr.initSlice("PATH")) orelse EnvStr.initSlice(""); const resolved = which(&path_buf, PATH.slice(), this.bltn.parentCmd().base.shell.cwdZ(), arg) orelse { @@ -8068,7 +8068,7 @@ pub const Interpreter = struct { if (this.target_fd) |fd| { _ = fd; - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; _ = this.moveInDir(src, &buf); return; } @@ -8083,7 +8083,7 @@ pub const Interpreter = struct { } } - pub fn moveInDir(this: *@This(), src: [:0]const u8, buf: *[bun.MAX_PATH_BYTES]u8) bool { + pub fn moveInDir(this: *@This(), src: [:0]const u8, buf: *bun.PathBuffer) bool { const path_in_dir_ = bun.path.normalizeBuf(ResolvePath.basename(src), buf, .auto); if (path_in_dir_.len + 1 >= buf.len) { this.err = Syscall.Error.fromCode(bun.C.E.NAMETOOLONG, .rename); @@ -8109,7 +8109,7 @@ pub const Interpreter = struct { } fn moveMultipleIntoDir(this: *@This()) void { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; var fixed_alloc = std.heap.FixedBufferAllocator.init(buf[0..bun.MAX_PATH_BYTES]); for (this.sources) |src_raw| { @@ -8647,7 +8647,7 @@ pub const Interpreter = struct { // Check that non of the paths will delete the root { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const cwd = switch (Syscall.getcwd(&buf)) { .err => |err| { return .{ .err = err }; @@ -9045,7 +9045,7 @@ pub const Interpreter = struct { // Root, get cwd path on windows if (bun.Environment.isWindows) { if (this.parent_task == null) { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const cwd_path = switch (Syscall.getFdPath(this.task_manager.cwd, &buf)) { .result => |p| bun.default_allocator.dupeZ(u8, p) catch bun.outOfMemory(), .err => |err| { @@ -9271,7 +9271,7 @@ pub const Interpreter = struct { } } - pub fn bufJoin(this: *ShellRmTask, buf: *[bun.MAX_PATH_BYTES]u8, parts: []const []const u8, syscall_tag: Syscall.Tag) Maybe([:0]const u8) { + pub fn bufJoin(this: *ShellRmTask, buf: *bun.PathBuffer, parts: []const []const u8, syscall_tag: Syscall.Tag) Maybe([:0]const u8) { _ = syscall_tag; // autofix if (this.join_style == .posix) { @@ -9284,14 +9284,14 @@ pub const Interpreter = struct { .task = this, .child_of_dir = false, }; - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; switch (dir_task.kind_hint) { .idk, .file => return this.removeEntryFile(dir_task, dir_task.path, is_absolute, &buf, &remove_child_vtable), .dir => return this.removeEntryDir(dir_task, is_absolute, &buf), } } - fn removeEntryDir(this: *ShellRmTask, dir_task: *DirTask, is_absolute: bool, buf: *[bun.MAX_PATH_BYTES]u8) Maybe(void) { + fn removeEntryDir(this: *ShellRmTask, dir_task: *DirTask, is_absolute: bool, buf: *bun.PathBuffer) Maybe(void) { const path = dir_task.path; const dirfd = this.cwd; debug("removeEntryDir({s})", .{path}); @@ -9452,7 +9452,7 @@ pub const Interpreter = struct { const DummyRemoveFile = struct { var dummy: @This() = std.mem.zeroes(@This()); - pub fn onIsDir(this: *@This(), parent_dir_task: *DirTask, path: [:0]const u8, is_absolute: bool, buf: *[bun.MAX_PATH_BYTES]u8) Maybe(void) { + pub fn onIsDir(this: *@This(), parent_dir_task: *DirTask, path: [:0]const u8, is_absolute: bool, buf: *bun.PathBuffer) Maybe(void) { _ = this; // autofix _ = parent_dir_task; // autofix _ = path; // autofix @@ -9462,7 +9462,7 @@ pub const Interpreter = struct { return Maybe(void).success; } - pub fn onDirNotEmpty(this: *@This(), parent_dir_task: *DirTask, path: [:0]const u8, is_absolute: bool, buf: *[bun.MAX_PATH_BYTES]u8) Maybe(void) { + pub fn onDirNotEmpty(this: *@This(), parent_dir_task: *DirTask, path: [:0]const u8, is_absolute: bool, buf: *bun.PathBuffer) Maybe(void) { _ = this; // autofix _ = parent_dir_task; // autofix _ = path; // autofix @@ -9477,7 +9477,7 @@ pub const Interpreter = struct { task: *ShellRmTask, child_of_dir: bool, - pub fn onIsDir(this: *@This(), parent_dir_task: *DirTask, path: [:0]const u8, is_absolute: bool, buf: *[bun.MAX_PATH_BYTES]u8) Maybe(void) { + pub fn onIsDir(this: *@This(), parent_dir_task: *DirTask, path: [:0]const u8, is_absolute: bool, buf: *bun.PathBuffer) Maybe(void) { if (this.child_of_dir) { this.task.enqueueNoJoin(parent_dir_task, bun.default_allocator.dupeZ(u8, path) catch bun.outOfMemory(), .dir); return Maybe(void).success; @@ -9485,7 +9485,7 @@ pub const Interpreter = struct { return this.task.removeEntryDir(parent_dir_task, is_absolute, buf); } - pub fn onDirNotEmpty(this: *@This(), parent_dir_task: *DirTask, path: [:0]const u8, is_absolute: bool, buf: *[bun.MAX_PATH_BYTES]u8) Maybe(void) { + pub fn onDirNotEmpty(this: *@This(), parent_dir_task: *DirTask, path: [:0]const u8, is_absolute: bool, buf: *bun.PathBuffer) Maybe(void) { if (this.child_of_dir) return .{ .result = this.task.enqueueNoJoin(parent_dir_task, bun.default_allocator.dupeZ(u8, path) catch bun.outOfMemory(), .dir) }; return this.task.removeEntryDir(parent_dir_task, is_absolute, buf); } @@ -9497,7 +9497,7 @@ pub const Interpreter = struct { allow_enqueue: bool = true, enqueued: bool = false, - pub fn onIsDir(this: *@This(), parent_dir_task: *DirTask, path: [:0]const u8, is_absolute: bool, buf: *[bun.MAX_PATH_BYTES]u8) Maybe(void) { + pub fn onIsDir(this: *@This(), parent_dir_task: *DirTask, path: [:0]const u8, is_absolute: bool, buf: *bun.PathBuffer) Maybe(void) { _ = parent_dir_task; // autofix _ = path; // autofix _ = is_absolute; // autofix @@ -9507,7 +9507,7 @@ pub const Interpreter = struct { return Maybe(void).success; } - pub fn onDirNotEmpty(this: *@This(), parent_dir_task: *DirTask, path: [:0]const u8, is_absolute: bool, buf: *[bun.MAX_PATH_BYTES]u8) Maybe(void) { + pub fn onDirNotEmpty(this: *@This(), parent_dir_task: *DirTask, path: [:0]const u8, is_absolute: bool, buf: *bun.PathBuffer) Maybe(void) { _ = is_absolute; // autofix _ = buf; // autofix @@ -9553,7 +9553,7 @@ pub const Interpreter = struct { }, } } else { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; if (this.removeEntryFile(dir_task, dir_task.path, dir_task.is_absolute, &buf, &state).asErr()) |e| { return .{ .err = e }; } @@ -9564,17 +9564,17 @@ pub const Interpreter = struct { } } - fn removeEntryFile(this: *ShellRmTask, parent_dir_task: *DirTask, path: [:0]const u8, is_absolute: bool, buf: *[bun.MAX_PATH_BYTES]u8, vtable: anytype) Maybe(void) { + fn removeEntryFile(this: *ShellRmTask, parent_dir_task: *DirTask, path: [:0]const u8, is_absolute: bool, buf: *bun.PathBuffer, vtable: anytype) Maybe(void) { const VTable = std.meta.Child(@TypeOf(vtable)); const Handler = struct { - pub fn onIsDir(vtable_: anytype, parent_dir_task_: *DirTask, path_: [:0]const u8, is_absolute_: bool, buf_: *[bun.MAX_PATH_BYTES]u8) Maybe(void) { + pub fn onIsDir(vtable_: anytype, parent_dir_task_: *DirTask, path_: [:0]const u8, is_absolute_: bool, buf_: *bun.PathBuffer) Maybe(void) { if (@hasDecl(VTable, "onIsDir")) { return VTable.onIsDir(vtable_, parent_dir_task_, path_, is_absolute_, buf_); } return Maybe(void).success; } - pub fn onDirNotEmpty(vtable_: anytype, parent_dir_task_: *DirTask, path_: [:0]const u8, is_absolute_: bool, buf_: *[bun.MAX_PATH_BYTES]u8) Maybe(void) { + pub fn onDirNotEmpty(vtable_: anytype, parent_dir_task_: *DirTask, path_: [:0]const u8, is_absolute_: bool, buf_: *bun.PathBuffer) Maybe(void) { if (@hasDecl(VTable, "onDirNotEmpty")) { return VTable.onDirNotEmpty(vtable_, parent_dir_task_, path_, is_absolute_, buf_); } @@ -10586,8 +10586,8 @@ pub const Interpreter = struct { } fn runFromThreadPoolImpl(this: *ShellCpTask) ?bun.shell.ShellErr { - var buf2: [bun.MAX_PATH_BYTES]u8 = undefined; - var buf3: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf2: bun.PathBuffer = undefined; + var buf3: bun.PathBuffer = undefined; // We have to give an absolute path to our cp // implementation for it to work with cwd const src: [:0]const u8 = brk: { @@ -11952,7 +11952,7 @@ pub const IOWriterChildPtr = struct { const ShellSyscall = struct { pub const unlinkatWithFlags = Syscall.unlinkatWithFlags; pub const rmdirat = Syscall.rmdirat; - fn getPath(dirfd: anytype, to: [:0]const u8, buf: *[bun.MAX_PATH_BYTES]u8) Maybe([:0]const u8) { + fn getPath(dirfd: anytype, to: [:0]const u8, buf: *bun.PathBuffer) Maybe([:0]const u8) { if (bun.Environment.isPosix) @compileError("Don't use this"); if (bun.strings.eqlComptime(to[0..to.len], "/dev/null")) { return .{ .result = shell.WINDOWS_DEV_NULL }; @@ -11992,7 +11992,7 @@ const ShellSyscall = struct { fn statat(dir: bun.FileDescriptor, path_: [:0]const u8) Maybe(bun.Stat) { if (bun.Environment.isWindows) { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const path = switch (getPath(dir, path_, &buf)) { .err => |e| return .{ .err = e }, .result => |p| p, @@ -12011,7 +12011,7 @@ const ShellSyscall = struct { if (bun.Environment.isWindows) { if (flags & os.O.DIRECTORY != 0) { if (ResolvePath.Platform.posix.isAbsolute(path[0..path.len])) { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const p = switch (getPath(dir, path, &buf)) { .result => |p| p, .err => |e| return .{ .err = e }, @@ -12027,7 +12027,7 @@ const ShellSyscall = struct { }; } - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var buf: bun.PathBuffer = undefined; const p = switch (getPath(dir, path, &buf)) { .result => |p| p, .err => |e| return .{ .err = e }, diff --git a/src/sourcemap/sourcemap.zig b/src/sourcemap/sourcemap.zig index 7eb950d76a3b9b..ab221f53c82f09 100644 --- a/src/sourcemap/sourcemap.zig +++ b/src/sourcemap/sourcemap.zig @@ -1509,7 +1509,7 @@ pub const Chunk = struct { // attempt to pre-allocate - var filename_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var filename_buf: bun.PathBuffer = undefined; var filename = source.path.text; if (strings.hasPrefix(source.path.text, FileSystem.instance.top_level_dir)) { filename = filename[FileSystem.instance.top_level_dir.len - 1 ..]; diff --git a/src/string_immutable.zig b/src/string_immutable.zig index f47d0f174b985f..74a6c65f78c197 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -1698,7 +1698,7 @@ pub fn toWPathNormalizeAutoExtend(wbuf: []u16, utf8: []const u8) [:0]const u16 { } pub fn toWPathNormalized(wbuf: []u16, utf8: []const u8) [:0]const u16 { - var renormalized: [bun.MAX_PATH_BYTES]u8 = undefined; + var renormalized: bun.PathBuffer = undefined; var path_to_use = normalizeSlashesOnly(&renormalized, utf8, '\\'); @@ -1728,7 +1728,7 @@ pub fn normalizeSlashesOnly(buf: []u8, utf8: []const u8, comptime desired_slash: } pub fn toWDirNormalized(wbuf: []u16, utf8: []const u8) [:0]const u16 { - var renormalized: [bun.MAX_PATH_BYTES]u8 = undefined; + var renormalized: bun.PathBuffer = undefined; var path_to_use = utf8; if (bun.strings.containsChar(utf8, '/')) { diff --git a/src/sys.zig b/src/sys.zig index c54e15e51d77af..5d118cec702566 100644 --- a/src/sys.zig +++ b/src/sys.zig @@ -340,7 +340,7 @@ pub fn Maybe(comptime ReturnTypeT: type) type { return JSC.Node.Maybe(ReturnTypeT, Error); } -pub fn getcwd(buf: *[bun.MAX_PATH_BYTES]u8) Maybe([]const u8) { +pub fn getcwd(buf: *bun.PathBuffer) Maybe([]const u8) { const Result = Maybe([]const u8); buf[0] = 0; const rc = std.c.getcwd(buf, bun.MAX_PATH_BYTES); diff --git a/src/which.zig b/src/which.zig index 89611485019925..093b141c4f6ced 100644 --- a/src/which.zig +++ b/src/which.zig @@ -132,7 +132,7 @@ fn searchBinInPath(buf: *bun.WPathBuffer, path_buf: *bun.PathBuffer, path: []con /// It is similar to Get-Command in powershell. pub fn whichWin(buf: *bun.WPathBuffer, path: []const u8, cwd: []const u8, bin: []const u8) ?[:0]const u16 { if (bin.len == 0) return null; - var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var path_buf: bun.PathBuffer = undefined; const check_windows_extensions = !endsWithExtension(bin);