diff options
author | 2022-01-02 00:04:03 -0800 | |
---|---|---|
committer | 2022-01-02 00:04:03 -0800 | |
commit | 2fc6da125f276cc96ab2131fa7cca63f41cfce6c (patch) | |
tree | d526ae872d666e7d3f7471f869014deb5d1a38a6 | |
parent | ba4013816dde7fca18b9f6686e688082cc5434a6 (diff) | |
download | bun-2fc6da125f276cc96ab2131fa7cca63f41cfce6c.tar.gz bun-2fc6da125f276cc96ab2131fa7cca63f41cfce6c.tar.zst bun-2fc6da125f276cc96ab2131fa7cca63f41cfce6c.zip |
[libarchive] Allow passing a Dir fd instead of always creating a new dir
-rw-r--r-- | src/libarchive/libarchive.zig | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/src/libarchive/libarchive.zig b/src/libarchive/libarchive.zig index 646d5b8f0..9e960d1a6 100644 --- a/src/libarchive/libarchive.zig +++ b/src/libarchive/libarchive.zig @@ -457,9 +457,9 @@ pub const Archive = struct { } } - pub fn extractToDisk( + pub fn extractToDir( file_buffer: []const u8, - root: []const u8, + dir: std.fs.Dir, ctx: ?*Archive.Context, comptime FilePathAppender: type, appender: FilePathAppender, @@ -476,21 +476,6 @@ pub const Archive = struct { var archive = stream.archive; var count: u32 = 0; - var dir: std.fs.Dir = brk: { - const cwd = std.fs.cwd(); - cwd.makePath( - root, - ) catch {}; - - if (std.fs.path.isAbsolute(root)) { - break :brk try std.fs.openDirAbsolute(root, .{ .iterate = true }); - } else { - break :brk try cwd.openDir(root, .{ .iterate = true }); - } - }; - - defer if (comptime close_handles) dir.close(); - loop: while (true) { const r = @intToEnum(Status, lib.archive_read_next_header(archive, &entry)); @@ -567,4 +552,31 @@ pub const Archive = struct { return count; } + + pub fn extractToDisk( + file_buffer: []const u8, + root: []const u8, + ctx: ?*Archive.Context, + comptime FilePathAppender: type, + appender: FilePathAppender, + comptime depth_to_skip: usize, + comptime close_handles: bool, + comptime log: bool, + ) !u32 { + var dir: std.fs.Dir = brk: { + const cwd = std.fs.cwd(); + cwd.makePath( + root, + ) catch {}; + + if (std.fs.path.isAbsolute(root)) { + break :brk try std.fs.openDirAbsolute(root, .{ .iterate = true }); + } else { + break :brk try cwd.openDir(root, .{ .iterate = true }); + } + }; + + defer if (comptime close_handles) dir.close(); + return try extractToDir(file_buffer, dir, ctx, FilePathAppender, appender, depth_to_skip, close_handles, log); + } }; |