diff options
Diffstat (limited to 'src/install')
-rw-r--r-- | src/install/bin.zig | 26 | ||||
-rw-r--r-- | src/install/extract_tarball.zig | 4 | ||||
-rw-r--r-- | src/install/install.zig | 173 | ||||
-rw-r--r-- | src/install/lockfile.zig | 29 | ||||
-rw-r--r-- | src/install/repository.zig | 4 |
5 files changed, 143 insertions, 93 deletions
diff --git a/src/install/bin.zig b/src/install/bin.zig index adbd5f4d3..b559f4f53 100644 --- a/src/install/bin.zig +++ b/src/install/bin.zig @@ -172,7 +172,7 @@ pub const Bin = extern struct { done: bool = false, dir_iterator: ?std.fs.IterableDir.Iterator = null, package_name: String, - package_installed_node_modules: std.fs.Dir = std.fs.Dir{ .fd = std.math.maxInt(std.os.fd_t) }, + package_installed_node_modules: std.fs.Dir = std.fs.Dir{ .fd = bun.fdcast(bun.invalid_fd) }, buf: [bun.MAX_PATH_BYTES]u8 = undefined, string_buffer: []const u8, extern_string_buf: []const ExternalString, @@ -257,8 +257,8 @@ pub const Bin = extern struct { pub const Linker = struct { bin: Bin, - package_installed_node_modules: std.os.fd_t = std.math.maxInt(std.os.fd_t), - root_node_modules_folder: std.os.fd_t = std.math.maxInt(std.os.fd_t), + package_installed_node_modules: bun.FileDescriptor = bun.invalid_fd, + root_node_modules_folder: bun.FileDescriptor = bun.invalid_fd, /// Used for generating relative paths package_name: strings.StringOrTinyString, @@ -290,6 +290,10 @@ pub const Bin = extern struct { } fn setSimlinkAndPermissions(this: *Linker, target_path: [:0]const u8, dest_path: [:0]const u8) void { + if (comptime Environment.isWindows) { + bun.todo(@src(), {}); + return; + } std.os.symlinkatZ(target_path, this.root_node_modules_folder, dest_path) catch |err| { // Silently ignore PathAlreadyExists // Most likely, the symlink was already created by another package @@ -320,7 +324,7 @@ pub const Bin = extern struct { var remain: []u8 = &dest_buf; if (!link_global) { - const root_dir = std.fs.Dir{ .fd = this.root_node_modules_folder }; + const root_dir = std.fs.Dir{ .fd = bun.fdcast(this.root_node_modules_folder) }; const from = root_dir.realpath(dot_bin, &target_buf) catch |err| { this.err = err; return; @@ -337,7 +341,7 @@ pub const Bin = extern struct { from_remain[0..dot_bin.len].* = dot_bin.*; from_remain = from_remain[dot_bin.len..]; } else { - if (this.global_bin_dir.fd >= std.math.maxInt(std.os.fd_t)) { + if (bun.toFD(this.global_bin_dir.fd) == bun.invalid_fd) { this.err = error.MissingGlobalBinDir; return; } @@ -354,7 +358,7 @@ pub const Bin = extern struct { remain[0] = std.fs.path.sep; remain = remain[1..]; - this.root_node_modules_folder = this.global_bin_dir.fd; + this.root_node_modules_folder = bun.toFD(this.global_bin_dir.fd); } const name = this.package_name.slice(); @@ -364,7 +368,9 @@ pub const Bin = extern struct { remain = remain[1..]; if (comptime Environment.isWindows) { - @compileError("Bin.Linker.link() needs to be updated to generate .cmd files on Windows"); + // TODO: Bin.Linker.link() needs to be updated to generate .cmd files on Windows + bun.todo(@src(), {}); + return; } switch (this.bin.tag) { @@ -458,7 +464,7 @@ pub const Bin = extern struct { bun.copy(u8, remain, target); remain = remain[target.len..]; - var dir = std.fs.Dir{ .fd = this.package_installed_node_modules }; + var dir = std.fs.Dir{ .fd = bun.fdcast(this.package_installed_node_modules) }; var joined = Path.joinStringBuf(&target_buf, &parts, .auto); @as([*]u8, @ptrFromInt(@intFromPtr(joined.ptr)))[joined.len] = 0; @@ -514,7 +520,7 @@ pub const Bin = extern struct { dest_buf[0.."../".len].* = "../".*; remain = dest_buf["../".len..]; } else { - if (this.global_bin_dir.fd >= std.math.maxInt(std.os.fd_t)) { + if (this.global_bin_dir.fd >= bun.invalid_fd) { this.err = error.MissingGlobalBinDir; return; } @@ -610,7 +616,7 @@ pub const Bin = extern struct { bun.copy(u8, remain, target); remain = remain[target.len..]; - var dir = std.fs.Dir{ .fd = this.package_installed_node_modules }; + var dir = std.fs.Dir{ .fd = bun.fdcast(this.package_installed_node_modules) }; var joined = Path.joinStringBuf(&target_buf, &parts, .auto); @as([*]u8, @ptrFromInt(@intFromPtr(joined.ptr)))[joined.len] = 0; diff --git a/src/install/extract_tarball.zig b/src/install/extract_tarball.zig index a533a92a7..2bcad3a53 100644 --- a/src/install/extract_tarball.zig +++ b/src/install/extract_tarball.zig @@ -354,8 +354,8 @@ fn extract(this: *const ExtractTarball, tgz_bytes: []const u8) !Install.ExtractD return error.InstallFailed; }; defer json_file.close(); - const json_stat = try json_file.stat(); - json_buf = try this.package_manager.allocator.alloc(u8, json_stat.size + 64); + const json_stat_size = try json_file.getEndPos(); + json_buf = try this.package_manager.allocator.alloc(u8, json_stat_size + 64); json_len = try json_file.preadAll(json_buf, 0); json_path = bun.getFdPath( diff --git a/src/install/install.zig b/src/install/install.zig index 868204ed6..ee23fa427 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -46,7 +46,7 @@ const ExtractTarball = @import("./extract_tarball.zig"); const Npm = @import("./npm.zig"); const Bitset = bun.bit_set.DynamicBitSetUnmanaged; const z_allocator = @import("../memory_allocator.zig").z_allocator; -const Syscall = bun.JSC.Node.Syscall; +const Syscall = bun.sys; const RunCommand = @import("../cli/run_command.zig").RunCommand; threadlocal var initialized_store = false; const Futex = @import("../futex.zig"); @@ -684,14 +684,14 @@ const Task = struct { ) catch |err| { this.err = err; this.status = Status.fail; - this.data = .{ .git_clone = std.math.maxInt(std.os.fd_t) }; + this.data = .{ .git_clone = bun.invalid_fd }; manager.resolve_tasks.writeItem(this.*) catch unreachable; return; }; - manager.git_repositories.put(manager.allocator, this.id, dir.fd) catch unreachable; + manager.git_repositories.put(manager.allocator, this.id, bun.toFD(dir.fd)) catch unreachable; this.data = .{ - .git_clone = dir.fd, + .git_clone = bun.toFD(dir.fd), }; this.status = Status.success; manager.resolve_tasks.writeItem(this.*) catch unreachable; @@ -703,7 +703,7 @@ const Task = struct { manager.env, manager.log, manager.getCacheDirectory().dir, - .{ .fd = this.request.git_checkout.repo_dir }, + .{ .fd = bun.fdcast(this.request.git_checkout.repo_dir) }, this.request.git_checkout.name.slice(), this.request.git_checkout.url.slice(), this.request.git_checkout.resolved.slice(), @@ -771,7 +771,7 @@ const Task = struct { pub const Data = union { package_manifest: Npm.PackageManifest, extract: ExtractData, - git_clone: std.os.fd_t, + git_clone: bun.FileDescriptor, git_checkout: ExtractData, }; @@ -791,7 +791,7 @@ const Task = struct { url: strings.StringOrTinyString, }, git_checkout: struct { - repo_dir: std.os.fd_t, + repo_dir: bun.FileDescriptor, dependency_id: DependencyID, name: strings.StringOrTinyString, url: strings.StringOrTinyString, @@ -1211,8 +1211,12 @@ const PackageInstall = struct { var infile = try entry.dir.dir.openFile(entry.basename, .{ .mode = .read_only }); defer infile.close(); - const stat = infile.stat() catch continue; - _ = C.fchmod(outfile.handle, stat.mode); + if (comptime Environment.isPosix) { + const stat = infile.stat() catch continue; + _ = C.fchmod(outfile.handle, stat.mode); + } else { + bun.todo(@src(), {}); + } bun.copyFile(infile.handle, outfile.handle) catch |err| { progress_.root.end(); @@ -1323,8 +1327,8 @@ const PackageInstall = struct { const FileCopier = struct { pub fn copy( - dest_dir_fd: std.os.fd_t, - cache_dir_fd: std.os.fd_t, + dest_dir_fd: bun.FileDescriptor, + cache_dir_fd: bun.FileDescriptor, walker: *Walker, ) !u32 { var real_file_count: u32 = 0; @@ -1352,7 +1356,7 @@ const PackageInstall = struct { switch (entry.kind) { // directories are created .directory => { - std.os.mkdirat(dest_dir_fd, entry.path, 0o755) catch {}; + std.os.mkdirat(bun.fdcast(dest_dir_fd), entry.path, 0o755) catch {}; }, // but each file in the directory is a symlink .file => { @@ -1383,8 +1387,8 @@ const PackageInstall = struct { defer subdir.close(); this.file_count = FileCopier.copy( - subdir.dir.fd, - cached_package_dir.dir.fd, + bun.toFD(subdir.dir.fd), + bun.toFD(cached_package_dir.dir.fd), &walker_, ) catch |err| return Result{ @@ -1408,7 +1412,7 @@ const PackageInstall = struct { const rc = Syscall.system.open(path, @as(u32, std.os.O.PATH | 0), @as(u32, 0)); switch (Syscall.getErrno(rc)) { .SUCCESS => { - const fd = @as(std.os.fd_t, @intCast(rc)); + const fd = @as(bun.FileDescriptor, @intCast(rc)); _ = Syscall.system.close(fd); return false; }, @@ -1462,7 +1466,17 @@ const PackageInstall = struct { }, }; const target = Path.relative(dest_dir_path, to_path); - + if (comptime Environment.isWindows) { + return bun.todo( + @src(), + Result{ + .fail = .{ + .err = error.NotImplementedYetOnWindows, + .step = .linking, + }, + }, + ); + } std.os.symlinkat(target, dest_dir.fd, std.fs.path.basename(dest_path)) catch |err| return Result{ .fail = .{ .err = err, @@ -1556,16 +1570,20 @@ const PackageInstall = struct { } }, .symlink => { - if (this.installWithSymlink()) |result| { - return result; - } else |err| { - switch (err) { - error.FileNotFound => return Result{ - .fail = .{ .err = error.FileNotFound, .step = .opening_cache_dir }, - }, - else => return Result{ - .fail = .{ .err = err, .step = .copying_files }, - }, + if (comptime Environment.isWindows) { + supported_method_to_use = .copyfile; + } else { + if (this.installWithSymlink()) |result| { + return result; + } else |err| { + switch (err) { + error.FileNotFound => return Result{ + .fail = .{ .err = error.FileNotFound, .step = .opening_cache_dir }, + }, + else => return Result{ + .fail = .{ .err = err, .step = .copying_files }, + }, + } } } }, @@ -1586,7 +1604,7 @@ const Progress = std.Progress; const TaggedPointer = @import("../tagged_pointer.zig"); const TaskCallbackContext = union(Tag) { dependency: DependencyID, - node_modules_folder: std.os.fd_t, + node_modules_folder: bun.FileDescriptor, root_dependency: DependencyID, root_request_id: PackageID, pub const Tag = enum { @@ -1603,7 +1621,7 @@ const TaskChannel = sync.Channel(Task, .{ .Static = 4096 }); const NetworkChannel = sync.Channel(*NetworkTask, .{ .Static = 8192 }); const ThreadPool = bun.ThreadPool; const PackageManifestMap = std.HashMapUnmanaged(PackageNameHash, Npm.PackageManifest, IdentityContext(PackageNameHash), 80); -const RepositoryMap = std.HashMapUnmanaged(u64, std.os.fd_t, IdentityContext(u64), 80); +const RepositoryMap = std.HashMapUnmanaged(u64, bun.FileDescriptor, IdentityContext(u64), 80); pub const CacheLevel = struct { use_cache_control_headers: bool, @@ -2726,7 +2744,7 @@ pub const PackageManager = struct { fn enqueueGitCheckout( this: *PackageManager, task_id: u64, - dir: std.os.fd_t, + dir: bun.FileDescriptor, dependency_id: DependencyID, name: string, resolution: Resolution, @@ -2837,11 +2855,13 @@ pub const PackageManager = struct { try Lockfile.Printer.Yarn.print(&printer, @TypeOf(writer), writer); try buffered_writer.flush(); - _ = C.fchmod( - tmpfile.fd, - // chmod 666, - 0o0000040 | 0o0000004 | 0o0000002 | 0o0000400 | 0o0000200 | 0o0000020, - ); + if (comptime Environment.isPosix) { + _ = C.fchmod( + tmpfile.fd, + // chmod 666, + 0o0000040 | 0o0000004 | 0o0000002 | 0o0000400 | 0o0000200 | 0o0000020, + ); + } try tmpfile.promote(tmpname, std.fs.cwd().fd, "yarn.lock"); } @@ -3102,7 +3122,7 @@ pub const PackageManager = struct { this.allocator, this.env, this.log, - .{ .fd = repo_fd }, + .{ .fd = bun.fdcast(repo_fd) }, alias, this.lockfile.str(&dep.committish), ); @@ -4304,7 +4324,7 @@ pub const PackageManager = struct { log_level: LogLevel = .default, global: bool = false, - global_bin_dir: std.fs.IterableDir = .{ .dir = .{ .fd = std.math.maxInt(std.os.fd_t) } }, + global_bin_dir: std.fs.IterableDir = .{ .dir = .{ .fd = bun.fdcast(bun.invalid_fd) } }, explicit_global_directory: string = "", /// destination directory to link bins into // must be a variable due to global installs and bunx @@ -5165,8 +5185,8 @@ pub const PackageManager = struct { continue; }; defer if (!found) json_file.close(); - const json_stat = try json_file.stat(); - const json_buf = try ctx.allocator.alloc(u8, json_stat.size + 64); + const json_stat_size = try json_file.getEndPos(); + const json_buf = try ctx.allocator.alloc(u8, json_stat_size + 64); defer ctx.allocator.free(json_buf); const json_len = try json_file.preadAll(json_buf, 0); const json_path = try bun.getFdPath(json_file.handle, &package_json_cwd_buf); @@ -5215,7 +5235,7 @@ pub const PackageManager = struct { break :brk child_json; }; - try std.os.chdir(fs.top_level_dir); + try bun.sys.chdir(fs.top_level_dir).throw(); try BunArguments.loadConfig(ctx.allocator, cli.config, ctx, .InstallCommand); bun.copy(u8, &cwd_buf, fs.top_level_dir); cwd_buf[fs.top_level_dir.len] = '/'; @@ -5454,6 +5474,11 @@ pub const PackageManager = struct { } pub inline fn link(ctx: Command.Context) !void { + if (comptime Environment.isWindows) { + Output.prettyErrorln("<r><red>error:<r> bun link is not supported on Windows yet", .{}); + Global.crash(); + } + var manager = PackageManager.init(ctx, .link) catch |err| brk: { if (err == error.MissingPackageJSON) { try attemptToCreatePackageJSON(); @@ -5477,8 +5502,8 @@ pub const PackageManager = struct { // Step 1. parse the nearest package.json file { - var current_package_json_stat = try manager.root_package_json_file.stat(); - var current_package_json_buf = try ctx.allocator.alloc(u8, current_package_json_stat.size + 64); + var current_package_json_stat_size = try manager.root_package_json_file.getEndPos(); + var current_package_json_buf = try ctx.allocator.alloc(u8, current_package_json_stat_size + 64); const current_package_json_contents_len = try manager.root_package_json_file.preadAll( current_package_json_buf, 0, @@ -5604,6 +5629,11 @@ pub const PackageManager = struct { } pub inline fn unlink(ctx: Command.Context) !void { + if (comptime Environment.isWindows) { + Output.prettyErrorln("<r><red>error:<r> bun unlink is not supported on Windows yet", .{}); + Global.crash(); + } + var manager = PackageManager.init(ctx, .unlink) catch |err| brk: { if (err == error.MissingPackageJSON) { try attemptToCreatePackageJSON(); @@ -5627,8 +5657,8 @@ pub const PackageManager = struct { // Step 1. parse the nearest package.json file { - var current_package_json_stat = try manager.root_package_json_file.stat(); - var current_package_json_buf = try ctx.allocator.alloc(u8, current_package_json_stat.size + 64); + var current_package_json_stat_size = try manager.root_package_json_file.getEndPos(); + var current_package_json_buf = try ctx.allocator.alloc(u8, current_package_json_stat_size + 64); const current_package_json_contents_len = try manager.root_package_json_file.preadAll( current_package_json_buf, 0, @@ -5943,7 +5973,7 @@ pub const PackageManager = struct { buf[cwd_.len] = 0; final_path = buf[0..cwd_.len :0]; } - try std.os.chdirZ(final_path); + try bun.sys.chdir(final_path).throw(); } const specified_backend: ?PackageInstall.Method = brk: { @@ -6244,8 +6274,8 @@ pub const PackageManager = struct { Global.crash(); } - var current_package_json_stat = try manager.root_package_json_file.stat(); - var current_package_json_buf = try ctx.allocator.alloc(u8, current_package_json_stat.size + 64); + var current_package_json_stat_size = try manager.root_package_json_file.getEndPos(); + var current_package_json_buf = try ctx.allocator.alloc(u8, current_package_json_stat_size + 64); const current_package_json_contents_len = try manager.root_package_json_file.preadAll( current_package_json_buf, 0, @@ -6593,7 +6623,7 @@ pub const PackageManager = struct { const prev_node_modules_folder = this.node_modules_folder; defer this.node_modules_folder = prev_node_modules_folder; for (callbacks.items) |cb| { - this.node_modules_folder = .{ .dir = .{ .fd = cb.node_modules_folder } }; + this.node_modules_folder = .{ .dir = .{ .fd = bun.fdcast(cb.node_modules_folder) } }; this.installPackageWithNameAndResolution(dependency_id, package_id, log_level, name, resolution); } } @@ -6753,9 +6783,14 @@ pub const PackageManager = struct { if (bin.tag != .none) { if (!this.has_created_bin) { if (!this.options.global) { - this.root_node_modules_folder.dir.makeDirZ(".bin") catch {}; + if (comptime Environment.isWindows) { + std.os.mkdiratW(this.root_node_modules_folder.dir.fd, strings.w(".bin"), 0) catch {}; + } else { + this.root_node_modules_folder.dir.makeDirZ(".bin") catch {}; + } } - Bin.Linker.umask = C.umask(0); + if (comptime Environment.isPosix) + Bin.Linker.umask = C.umask(0); this.has_created_bin = true; } @@ -6773,12 +6808,12 @@ pub const PackageManager = struct { var bin_linker = Bin.Linker{ .bin = bin, - .package_installed_node_modules = this.node_modules_folder.dir.fd, + .package_installed_node_modules = bun.toFD(this.node_modules_folder.dir.fd), .global_bin_path = this.options.bin_path, .global_bin_dir = this.options.global_bin_dir.dir, // .destination_dir_subpath = destination_dir_subpath, - .root_node_modules_folder = this.root_node_modules_folder.dir.fd, + .root_node_modules_folder = bun.toFD(this.root_node_modules_folder.dir.fd), .package_name = strings.StringOrTinyString.init(alias), .string_buf = buf, .extern_string_buf = extern_string_buf, @@ -6815,7 +6850,7 @@ pub const PackageManager = struct { if (scripts.hasAny()) { var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; const path_str = Path.joinAbsString( - bun.getFdPath(this.node_modules_folder.dir.fd, &path_buf) catch unreachable, + bun.getFdPath(bun.toFD(this.node_modules_folder.dir.fd), &path_buf) catch unreachable, &[_]string{destination_dir_subpath}, .posix, ); @@ -6824,7 +6859,7 @@ pub const PackageManager = struct { } else if (!scripts.filled) { var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; const path_str = Path.joinAbsString( - bun.getFdPath(this.node_modules_folder.dir.fd, &path_buf) catch unreachable, + bun.getFdPath(bun.toFD(this.node_modules_folder.dir.fd), &path_buf) catch unreachable, &[_]string{destination_dir_subpath}, .posix, ); @@ -6870,7 +6905,7 @@ pub const PackageManager = struct { dependency_id, alias, resolution, - .{ .node_modules_folder = this.node_modules_folder.dir.fd }, + .{ .node_modules_folder = bun.toFD(this.node_modules_folder.dir.fd) }, ); }, .github => { @@ -6880,7 +6915,7 @@ pub const PackageManager = struct { dependency_id, package_id, url, - .{ .node_modules_folder = this.node_modules_folder.dir.fd }, + .{ .node_modules_folder = bun.toFD(this.node_modules_folder.dir.fd) }, ); }, .local_tarball => { @@ -6888,7 +6923,7 @@ pub const PackageManager = struct { dependency_id, alias, resolution, - .{ .node_modules_folder = this.node_modules_folder.dir.fd }, + .{ .node_modules_folder = bun.toFD(this.node_modules_folder.dir.fd) }, ); }, .remote_tarball => { @@ -6896,7 +6931,7 @@ pub const PackageManager = struct { dependency_id, package_id, resolution.value.remote_tarball.slice(buf), - .{ .node_modules_folder = this.node_modules_folder.dir.fd }, + .{ .node_modules_folder = bun.toFD(this.node_modules_folder.dir.fd) }, ); }, .npm => { @@ -6907,7 +6942,7 @@ pub const PackageManager = struct { package_id, resolution.value.npm.version, resolution.value.npm.url.slice(buf), - .{ .node_modules_folder = this.node_modules_folder.dir.fd }, + .{ .node_modules_folder = bun.toFD(this.node_modules_folder.dir.fd) }, ); }, else => { @@ -7149,13 +7184,14 @@ pub const PackageManager = struct { // we want to check lazily though // no need to download packages you've already installed!! var skip_verify_installed_version_number = false; - var node_modules_folder = std.fs.cwd().openIterableDir("node_modules", .{}) catch brk: { + const cwd = std.fs.cwd(); + var node_modules_folder = cwd.openIterableDir("node_modules", .{}) catch brk: { skip_verify_installed_version_number = true; - std.fs.cwd().makeDirZ("node_modules") catch |err| { + (if (comptime Environment.isWindows) std.os.mkdiratW(cwd.fd, bun.strings.w("node_modules"), 0) else cwd.makeDirZ("node_modules")) catch |err| { Output.prettyErrorln("<r><red>error<r>: <b><red>{s}<r> creating <b>node_modules<r> folder", .{@errorName(err)}); Global.crash(); }; - break :brk std.fs.cwd().openIterableDir("node_modules", .{}) catch |err| { + break :brk cwd.openIterableDir("node_modules", .{}) catch |err| { Output.prettyErrorln("<r><red>error<r>: <b><red>{s}<r> opening <b>node_modules<r> folder", .{@errorName(err)}); Global.crash(); }; @@ -7204,8 +7240,6 @@ pub const PackageManager = struct { ), }; - const cwd = std.fs.cwd(); - while (iterator.nextNodeModulesFolder()) |node_modules| { // We deliberately do not close this folder. // If the package hasn't been downloaded, we will need to install it later @@ -7305,16 +7339,21 @@ pub const PackageManager = struct { if (!installer.has_created_bin) { if (!this.options.global) { - node_modules_folder.dir.makeDirZ(".bin") catch {}; + if (comptime Environment.isWindows) { + std.os.mkdiratW(node_modules_folder.dir.fd, bun.strings.w(".bin"), 0) catch {}; + } else { + node_modules_folder.dir.makeDirZ(".bin") catch {}; + } } - Bin.Linker.umask = C.umask(0); + if (comptime Environment.isPosix) + Bin.Linker.umask = C.umask(0); installer.has_created_bin = true; } var bin_linker = Bin.Linker{ .bin = original_bin, - .package_installed_node_modules = folder.dir.fd, - .root_node_modules_folder = node_modules_folder.dir.fd, + .package_installed_node_modules = bun.toFD(folder.dir.fd), + .root_node_modules_folder = bun.toFD(node_modules_folder.dir.fd), .global_bin_path = this.options.bin_path, .global_bin_dir = this.options.global_bin_dir.dir, diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index 5a085d92b..753d22857 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -915,7 +915,7 @@ pub const Printer = struct { } if (lockfile_path.len > 0 and lockfile_path[0] == std.fs.path.sep) - std.os.chdir(std.fs.path.dirname(lockfile_path) orelse "/") catch {}; + _ = bun.sys.chdir(std.fs.path.dirname(lockfile_path) orelse std.fs.path.sep_str); _ = try FileSystem.init(null); @@ -1473,11 +1473,16 @@ pub fn saveToDisk(this: *Lockfile, filename: stringZ) void { Global.crash(); }; - _ = C.fchmod( - tmpfile.fd, - // chmod 777 - 0o0000010 | 0o0000100 | 0o0000001 | 0o0001000 | 0o0000040 | 0o0000004 | 0o0000002 | 0o0000400 | 0o0000200 | 0o0000020, - ); + if (comptime Environment.isWindows) { + // TODO: make this executable + bun.todo(@src(), {}); + } else { + _ = C.fchmod( + tmpfile.fd, + // chmod 777 + 0o0000010 | 0o0000100 | 0o0000001 | 0o0001000 | 0o0000040 | 0o0000004 | 0o0000002 | 0o0000400 | 0o0000200 | 0o0000020, + ); + } tmpfile.promote(tmpname, std.fs.cwd().fd, filename) catch |err| { tmpfile.dir().deleteFileZ(tmpname) catch {}; @@ -1898,8 +1903,8 @@ pub const Package = extern struct { defer pkg_dir.close(); const json_file = try pkg_dir.dir.openFileZ("package.json", .{ .mode = .read_only }); defer json_file.close(); - const json_stat = try json_file.stat(); - const json_buf = try lockfile.allocator.alloc(u8, json_stat.size + 64); + const json_stat_size = try json_file.getEndPos(); + const json_buf = try lockfile.allocator.alloc(u8, json_stat_size + 64); const json_len = try json_file.preadAll(json_buf, 0); const json_src = logger.Source.initPathString(cwd, json_buf[0..json_len]); initializeStore(); @@ -3065,12 +3070,12 @@ pub const Package = extern struct { ); if (entry.cache.fd == 0) { - entry.cache.fd = std.os.openatZ( - std.os.AT.FDCWD, + entry.cache.fd = bun.toFD(std.os.openatZ( + std.fs.cwd().fd, entry_path, std.os.O.DIRECTORY | std.os.O.CLOEXEC | std.os.O.NOCTTY, 0, - ) catch continue; + ) catch continue); } const dir_fd = entry.cache.fd; @@ -3081,7 +3086,7 @@ pub const Package = extern struct { allocator, workspace_allocator, std.fs.Dir{ - .fd = dir_fd, + .fd = bun.fdcast(dir_fd), }, "", filepath_buf, diff --git a/src/install/repository.zig b/src/install/repository.zig index 6546481e9..564306733 100644 --- a/src/install/repository.zig +++ b/src/install/repository.zig @@ -284,8 +284,8 @@ pub const Repository = extern struct { return error.InstallFailed; }; defer json_file.close(); - const json_stat = try json_file.stat(); - var json_buf = try allocator.alloc(u8, json_stat.size + 64); + const size = try json_file.getEndPos(); + var json_buf = try allocator.alloc(u8, size + 64); const json_len = try json_file.preadAll(json_buf, 0); const json_path = bun.getFdPath( |