Skip to content

Commit 5b68673

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} and pax headers - allow them to be longer than 512 bytes by adding an allocator param to pipeToFileSystem(). * symlinks: cleanup logic and skip if wasi * use std.os.toPosixPath() instead of custom one. * on windows, use custom openDirW() which adds FILE_WRITE_ATTRIBUTES in attempt to fix ci errors. src/Package.zig: pass gpa to pipeToFileSystem() tests: minor cosmetic changes
1 parent cf081fa commit 5b68673

File tree

5 files changed

+248
-255
lines changed

5 files changed

+248
-255
lines changed

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
}

lib/std/compress/tar/reader_test.zig

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

28-
test "tar validate testdata headers" {
29-
// skip if wine and debug mode due to 'incorrect alignment'
30-
// TODO re-enable after https://github.com/ziglang/zig/issues/14036 is solved
28+
test "std.tar validate testdata headers" {
29+
// skip due to 'incorrect alignment', maybe the same as
30+
// https://github.com/ziglang/zig/issues/14036
3131
if (builtin.os.tag == .windows and builtin.mode == .Debug)
3232
return error.SkipZigTest;
3333

@@ -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]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

lib/std/compress/tar/test_decompress.zig

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

9-
test "tar decompress testdata" {
10-
// skip if wine and debug mode due to 'incorrect alignment'
11-
// TODO re-enable after https://github.com/ziglang/zig/issues/14036 is solved
9+
test "std.tar decompress testdata" {
10+
// skip due to 'incorrect alignment', maybe the same as
11+
// https://github.com/ziglang/zig/issues/14036
1212
if (builtin.os.tag == .windows and builtin.mode == .Debug)
1313
return error.SkipZigTest;
1414

@@ -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(talloc, tmpdir.dir, fbs.reader(), options);
48+
}

0 commit comments

Comments
 (0)