diff options
author | 2022-07-25 01:37:58 -0700 | |
---|---|---|
committer | 2022-07-25 01:37:58 -0700 | |
commit | 5a81acce3a359ed75bd84c6c26aa60b340d06df6 (patch) | |
tree | 9472daf1c062515cb34b62adab32a3cdcf65f4ec /src/libarchive | |
parent | 8a43083415747b969038b00dffe507617f78b77b (diff) | |
download | bun-5a81acce3a359ed75bd84c6c26aa60b340d06df6.tar.gz bun-5a81acce3a359ed75bd84c6c26aa60b340d06df6.tar.zst bun-5a81acce3a359ed75bd84c6c26aa60b340d06df6.zip |
[bun install] Fix `AccessDenied` error when installing some packages
Fixes https://github.com/oven-sh/bun/issues/728
Fixes https://github.com/oven-sh/bun/issues/867
Fixes https://github.com/oven-sh/bun/issues/135
Credit @SheetJSDev
Diffstat (limited to 'src/libarchive')
-rw-r--r-- | src/libarchive/libarchive.zig | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/libarchive/libarchive.zig b/src/libarchive/libarchive.zig index 749404037..909b26ac1 100644 --- a/src/libarchive/libarchive.zig +++ b/src/libarchive/libarchive.zig @@ -512,8 +512,18 @@ pub const Archive = struct { switch (kind) { Kind.Directory => { - const perm = @intCast(u32, lib.archive_entry_perm(entry)); - std.os.mkdiratZ(dir.fd, pathname, perm) catch |err| { + var mode = @intCast(i32, lib.archive_entry_perm(entry)); + + // if dirs are readable, then they should be listable + // https://github.com/npm/node-tar/blob/main/lib/mode-fix.js + if ((mode & 0o400) != 0) + mode |= 0o100; + if ((mode & 0o40) != 0) + mode |= 0o10; + if ((mode & 0o4) != 0) + mode |= 0o1; + + std.os.mkdiratZ(dir.fd, pathname, @intCast(u32, mode)) catch |err| { if (err == error.PathAlreadyExists or err == error.NotDir) break; try dir.makePath(std.fs.path.dirname(slice) orelse return err); try std.os.mkdiratZ(dir.fd, pathname, 0o777); |