Compare commits

...

2 Commits

Author SHA1 Message Date
claude[bot]
3cab11cb3f 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 <Jarred-Sumner@users.noreply.github.com>
2025-05-31 02:35:12 +00:00
Jarred Sumner
127fcf2d27 Avoid the copy up when installing symlinks
Closes https://github.com/oven-sh/bun/pull/20024
2025-05-30 01:06:05 -07:00

View File

@@ -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);
}
}
@@ -762,7 +765,16 @@ pub const Bin = extern struct {
fn createSymlink(this: *Linker, abs_target: [:0]const u8, abs_dest: [:0]const u8, global: bool) void {
defer {
if (this.err == null) {
_ = bun.sys.chmod(abs_target, umask | 0o777);
// 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 = 0o777 & ~umask;
if ((stat.mode & 0o777) != desired_mode) {
_ = bun.sys.chmod(abs_target, desired_mode);
}
},
.err => {},
}
}
}