aboutsummaryrefslogtreecommitdiff
path: root/src/libarchive/libarchive.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-24 22:26:45 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-24 22:27:06 -0800
commita3cc911e7a36388cdacb090b799059ed71f013bb (patch)
treebbfd7df5d143fa18f110c172fc12541d091e130f /src/libarchive/libarchive.zig
parentac7aff1b47b0b271d2afb010f3ffd199b9b6685d (diff)
downloadbun-a3cc911e7a36388cdacb090b799059ed71f013bb.tar.gz
bun-a3cc911e7a36388cdacb090b799059ed71f013bb.tar.zst
bun-a3cc911e7a36388cdacb090b799059ed71f013bb.zip
get cache key for github in one pass
Diffstat (limited to '')
-rw-r--r--src/libarchive/libarchive.zig45
1 files changed, 11 insertions, 34 deletions
diff --git a/src/libarchive/libarchive.zig b/src/libarchive/libarchive.zig
index 26eb5c5a3..adf9cdb4a 100644
--- a/src/libarchive/libarchive.zig
+++ b/src/libarchive/libarchive.zig
@@ -468,42 +468,12 @@ pub const Archive = struct {
}
}
- pub fn readFirstDirname(
- file_buffer: []const u8,
- ) !string {
- var entry: *lib.archive_entry = undefined;
-
- var stream: BufferReadStream = undefined;
- stream.init(file_buffer);
- defer stream.deinit();
- _ = stream.openRead();
- var archive = stream.archive;
-
- return brk: {
- while (true) {
- const r = @intToEnum(Status, lib.archive_read_next_header(archive, &entry));
-
- switch (r) {
- Status.eof => break,
- Status.retry => continue,
- Status.failed, Status.fatal => return error.Fail,
- else => {
- var pathname: [:0]const u8 = std.mem.sliceTo(lib.archive_entry_pathname(entry).?, 0);
- var tokenizer = std.mem.tokenize(u8, std.mem.span(pathname), std.fs.path.sep_str);
-
- if (tokenizer.next()) |name| break :brk name;
- },
- }
- }
- };
- }
-
pub fn extractToDir(
file_buffer: []const u8,
dir_: std.fs.IterableDir,
ctx: ?*Archive.Context,
- comptime FilePathAppender: type,
- appender: FilePathAppender,
+ comptime ContextType: type,
+ appender: ContextType,
comptime depth_to_skip: usize,
comptime close_handles: bool,
comptime log: bool,
@@ -527,7 +497,14 @@ pub const Archive = struct {
Status.retry => continue :loop,
Status.failed, Status.fatal => return error.Fail,
else => {
- var pathname: [:0]const u8 = std.mem.sliceTo(lib.archive_entry_pathname(entry).?, 0);
+ var pathname: [:0]const u8 = bun.sliceTo(lib.archive_entry_pathname(entry).?, 0);
+
+ if (comptime ContextType != void and @hasDecl(std.meta.Child(ContextType), "onFirstDirectoryName")) {
+ if (appender.needs_first_dirname) {
+ appender.onFirstDirectoryName(strings.withoutTrailingSlash(std.mem.span(pathname)));
+ }
+ }
+
var tokenizer = std.mem.tokenize(u8, std.mem.span(pathname), std.fs.path.sep_str);
comptime var depth_i: usize = 0;
@@ -610,7 +587,7 @@ pub const Archive = struct {
else
@as(u64, 0);
- if (comptime FilePathAppender != void) {
+ if (comptime ContextType != void and @hasDecl(std.meta.Child(ContextType), "appendMutable")) {
var result = ctx.?.all_files.getOrPutAdapted(hash, Context.U64Context{}) catch unreachable;
if (!result.found_existing) {
result.value_ptr.* = (try appender.appendMutable(@TypeOf(slice), slice)).ptr;