aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libarchive/libarchive.zig46
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);
+ }
};