Skip to content

Commit ad95885

Browse files
committed
std.tar: cleanups and fixes
tar.zig: * convert V7Header, UstarHeader, StarHeader, GnuHeader to have fields of byte arrays instead of accessor methods. * Header.getFormat() - optimize by using 64 bit compares rather than mem.eql(). * gnu_long{name,link} - allow for these to be longer than 512 bytes by using an internal heap.page_allocator backed arena in pipeToFileSystem(). * symlinks: cleanup logic and skip if wasi * use std.os.toPosixPath() instead of custom one. tests: minor cosmetic changes
1 parent cf081fa commit ad95885

File tree

4 files changed

+184
-234
lines changed

4 files changed

+184
-234
lines changed

Diff for: lib/std/compress/tar.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test "std.tar" {
1+
test {
22
_ = @import("tar/reader_test.zig");
33
_ = @import("tar/test_decompress.zig");
44
}

Diff for: lib/std/compress/tar/reader_test.zig

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const TestCase = struct {
2525
skip: bool = false, // Wether to skip test case
2626
};
2727

28-
test "tar validate testdata headers" {
28+
test "std.tar validate testdata headers" {
2929
// skip if wine and debug mode due to 'incorrect alignment'
3030
// TODO re-enable after https://github.com/ziglang/zig/issues/14036 is solved
3131
if (builtin.os.tag == .windows and builtin.mode == .Debug)
@@ -671,8 +671,9 @@ test "tar validate testdata headers" {
671671
var fbs = try test_common.decompressGz("testdata/" ++ test_case.file ++ ".gz", talloc);
672672
defer talloc.free(fbs.buffer);
673673
const reader = fbs.reader();
674-
var buf: [tar.block_len * 4]u8 = undefined;
675-
var iter = tar.headerIterator(reader, &buf);
674+
var buf: [tar.block_len * 2]u8 = undefined;
675+
var iter = tar.headerIterator(reader, &buf, talloc);
676+
defer iter.deinit();
676677
for (test_case.headers, 0..) |header_, i| {
677678
// since we don't maintain a hash map of pax records, merge pax_recs
678679
// into this header record

Diff for: lib/std/compress/tar/test_decompress.zig

+9-15
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const talloc = testing.allocator;
66
const builtin = @import("builtin");
77
const test_common = @import("test_common.zig");
88

9-
test "tar decompress testdata" {
9+
test "std.tar decompress testdata" {
1010
// skip if wine and debug mode due to 'incorrect alignment'
1111
// TODO re-enable after https://github.com/ziglang/zig/issues/14036 is solved
1212
if (builtin.os.tag == .windows and builtin.mode == .Debug)
@@ -32,23 +32,17 @@ test "tar decompress testdata" {
3232
"gnu-multi-hdrs.tar",
3333
};
3434

35-
var cache_dir = testing.tmpDir(.{});
36-
defer cache_dir.cleanup();
37-
3835
inline for (test_files) |test_file| {
3936
var fbs = try test_common.decompressGz("testdata/" ++ test_file ++ ".gz", talloc);
4037
defer talloc.free(fbs.buffer);
41-
{
42-
var output_dir = try cache_dir.dir.makeOpenPath(test_file, .{});
43-
defer output_dir.close();
44-
try tar.pipeToFileSystem(output_dir, fbs.reader(), .{ .mode_mode = .ignore });
45-
}
46-
try cache_dir.dir.deleteTree(test_file);
38+
try testDecompressTarToTmp(&fbs, .{ .mode_mode = .ignore });
4739
fbs.reset();
48-
{
49-
var output_dir = try cache_dir.dir.makeOpenPath(test_file, .{});
50-
defer output_dir.close();
51-
try tar.pipeToFileSystem(output_dir, fbs.reader(), .{ .mode_mode = .executable_bit_only });
52-
}
40+
try testDecompressTarToTmp(&fbs, .{ .mode_mode = .executable_bit_only });
5341
}
5442
}
43+
44+
fn testDecompressTarToTmp(fbs: *std.io.FixedBufferStream([]u8), options: tar.Options) !void {
45+
var tmpdir = testing.tmpDir(.{});
46+
defer tmpdir.cleanup();
47+
try tar.pipeToFileSystem(tmpdir.dir, fbs.reader(), options, talloc);
48+
}

0 commit comments

Comments
 (0)