From 3cab11cb3fffaeaaf39bf703c4a45b4e57e42cfa Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Sat, 31 May 2025 02:35:12 +0000 Subject: [PATCH] Fix umask handling in bin linking - Change `umask | 0o777` to `0o777 & ~umask` for correct permission calculation - Make `ensureUmask` restore the original umask instead of leaving it at zero Co-authored-by: Jarred-Sumner --- src/install/bin.zig | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/install/bin.zig b/src/install/bin.zig index 347cf026fd..eb3f137f0c 100644 --- a/src/install/bin.zig +++ b/src/install/bin.zig @@ -581,13 +581,16 @@ pub const Bin = extern struct { err: ?anyerror = null, pub var umask: bun.Mode = 0; + var original_umask: bun.Mode = 0; var has_set_umask = false; pub fn ensureUmask() void { if (!has_set_umask) { has_set_umask = true; - umask = bun.sys.umask(0); + original_umask = bun.sys.umask(0); + umask = original_umask; + _ = bun.sys.umask(original_umask); } } @@ -765,7 +768,7 @@ pub const Bin = extern struct { // An extra stat() is cheaper than a copy-up of potentially large executables in Docker. switch (bun.sys.stat(abs_target)) { .result => |*stat| { - const desired_mode = umask | 0o777; + const desired_mode = 0o777 & ~umask; if ((stat.mode & 0o777) != desired_mode) { _ = bun.sys.chmod(abs_target, desired_mode); }