diff --git a/src/install/bin.zig b/src/install/bin.zig index 5799ae51d1f312..c0dad86d6974d8 100644 --- a/src/install/bin.zig +++ b/src/install/bin.zig @@ -305,10 +305,19 @@ pub const Bin = extern struct { pub var umask: std.os.mode_t = 0; + var has_set_umask = false; + pub const Error = error{ NotImplementedYet, } || std.os.SymLinkError || std.os.OpenError || std.os.RealPathError; + pub fn ensureUmask() void { + if (!has_set_umask) { + has_set_umask = true; + umask = bun.C.umask(0); + } + } + fn unscopedPackageName(name: []const u8) []const u8 { if (name[0] != '@') return name; var name_ = name; @@ -371,10 +380,6 @@ pub const Bin = extern struct { }; } - if (comptime Environment.isPosix) { - Bin.Linker.umask = C.umask(0); - } - break :brk root_dir.realpath(dot_bin, &target_buf) catch |err| { this.err = err; return; diff --git a/src/install/install.zig b/src/install/install.zig index 139304dbc4579b..765d15882c7e9c 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -6155,7 +6155,7 @@ pub const PackageManager = struct { // Step 2. Setup the global directory var node_modules: std.fs.IterableDir = brk: { - Bin.Linker.umask = C.umask(0); + Bin.Linker.ensureUmask(); var explicit_global_dir: string = ""; if (ctx.install) |install_| { explicit_global_dir = install_.global_dir orelse explicit_global_dir; @@ -6323,7 +6323,7 @@ pub const PackageManager = struct { // Step 2. Setup the global directory var node_modules: std.fs.IterableDir = brk: { - Bin.Linker.umask = C.umask(0); + Bin.Linker.ensureUmask(); var explicit_global_dir: string = ""; if (ctx.install) |install_| { explicit_global_dir = install_.global_dir orelse explicit_global_dir; @@ -7901,7 +7901,9 @@ pub const PackageManager = struct { { var iterator = Lockfile.Tree.Iterator.init(lockfile); - + if (comptime Environment.isPosix) { + Bin.Linker.ensureUmask(); + } var installer: PackageInstaller = brk: { // These slices potentially get resized during iteration // so we want to make sure they're not accessible to the rest of this function