Skip to content

Commit

Permalink
Set umask once (oven-sh#7176)
Browse files Browse the repository at this point in the history
Co-authored-by: Jarred Sumner <[email protected]>
  • Loading branch information
Jarred-Sumner and Jarred-Sumner authored Nov 17, 2023
1 parent 538a243 commit 711ea16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/install/bin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/install/install.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 711ea16

Please sign in to comment.