Set umask once (#7176)

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2023-11-17 14:08:25 +01:00
committed by GitHub
parent 538a243453
commit 711ea1604b
2 changed files with 14 additions and 7 deletions

View File

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

View File

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