Commit Graph

23 Commits

Author SHA1 Message Date
Igor Anić
c4868b2bbc std.tar: use doctest
Make std.tar look better in docs. Remove from public interface what is
not necessary. Add comment to the public methods. Add doctest as usage
examples for iterator and pipeToFileSystem.
2024-03-11 12:25:03 +01:00
Igor Anić
8cc35a0255 std.tar: fix path testing on windows
Fixing ci error: error:

'tar.test.test.pipeToFileSystem' failed: slices differ. first difference occurs at index 2 (0x2)

============ expected this output: =============  len: 9 (0x9)

2E 2E 2F 61 2F 66 69 6C  65                       ../a/file

============= instead found this: ==============  len: 9 (0x9)

2E 2E 5C 61 5C 66 69 6C  65                       ..\a\file

After #19136 dir.symlink changes path separtors to \ on windows.
2024-03-11 12:24:11 +01:00
Igor Anić
614161a7cf std.tar make iterator interface more ergonomic
for the then end users:

1. Don't require user to call file.skip() on file returned from
iterator.next if file is not read. Iterator will now handle this.
Previously that returned header parsing error, without knowing some tar
internals it is hard to understand what is required from user.

2. Use iterator.File.kind enum which is similar to fs.File.Kind,
something familiar. Internal Header.Kind has many types which are not
exposed but the user needs to have else in kind switch to cover those
cases.

3. Add reader interface to the iterator.File.
2024-03-11 12:22:12 +01:00
Igor Anić
5ccbb196ad std.tar: don't return in iterator init
Don't assert min buffer size on iterator init. That was changing public
interface. This way we don't break that interface.
2024-03-11 12:22:12 +01:00
Igor Anić
10add7c677 std.tar: remove redundant test name prefixes 2024-03-11 12:22:12 +01:00
Igor Anić
04e8bbd932 std.tar: test buffers provided to the iterator
Tar header stores name in max 256 bytes and link name in max 100 bytes.
Those are minimums for provided buffers. Error is raised during iterator
init if buffers are not long enough.

Pax and gnu extensions can store longer names. If such extension is
reached during unpack and don't fit into provided buffer error is
returned.
2024-03-11 12:22:12 +01:00
Igor Anić
af0502f6c4 std.tar: add tests for file and symlink create
Should do that before I broke package manager!
2024-03-11 12:22:00 +01:00
Andrew Kelley
ffd53a459e -femit-docs: creating sources.tar
It's always a good day when you get to use File.writeFileAll 😎
2024-03-10 17:51:07 -07:00
Ryan Liptak
e80d4bc6f8 Re-enable and fix tar pipeToFileSystem test on Windows 2024-02-29 16:12:24 -08:00
Andrew Kelley
af06584241
Merge pull request #19126 from ianic/tar_case_sensitive
std.tar: fix unconditional error return
2024-02-29 10:12:39 -08:00
Igor Anić
e57800610b std.tar: disable test failing on windows
Just to pass ci of regression fix #19126.
I'll return to this later.
Currently can't reproduce on my Windows wm, here I'm failing on symlink creation
in ci fails later in the process.
2024-02-29 07:57:49 +01:00
Andrew Kelley
beca85e644 std.tar.iterator: make the buffers configurable
Provides more API flexibility and correctness, while still preserving
the handy high level `pipeToFileSystem` API.
2024-02-28 20:33:29 -07:00
Andrew Kelley
81aa74e7e1
Merge pull request #19081 from ianic/tar_case_sensitive
std.tar don't overwrite files on unpack
2024-02-26 12:23:22 -08:00
Igor Anić
f086ea856c std.tar skip test on windows
Or other platform which don't support symlinks.
2024-02-25 15:57:20 +01:00
Igor Anić
30a319be6d std.tar improve error reporting
Report file name which failed to create in all cases.
2024-02-25 12:03:23 +01:00
Igor Anić
96e4d56819 std.tar add case sensitive file name test
Like in issue #18089, this tar contains, same file name in two case
sensitive name version. Unpack should fail on case insensitive file
systems and succeed on case sensitive.

$ tar tvf 18089.tar
    18089/
    18089/alacritty/
    18089/alacritty/darkermatrix.yml
    18089/alacritty/Darkermatrix.yml
2024-02-25 10:35:18 +01:00
Igor Anić
b84301c8e5 std.tar don't overwrite existing file
Fail with error if file already exists. File is not silently overwritten
but an error is raised.

Fixes: #18089
2024-02-24 23:37:55 +01:00
Igor Anić
8d651f512b std.tar fix assert exploited by fuzzing 2024-02-24 13:17:04 -08:00
Igor Anić
30f15e3afe fix crash in tar found by fuzzing
Running fuzzing tar test with [zig std lib
fuzzing](https://github.com/squeek502/zig-std-lib-fuzzing) reached and
assert in tar implementation. Assert (in std lib) should not be
reachable by external input, so I'm fixing this to return error.
2024-02-22 18:20:05 -08:00
Igor Anić
7923a53996 tar: rename reader to iterator
Itarator has `next` function, iterates over tar files. When using from
outside of module with `tar.` prefix makes more sense.

var iter = tar.iterator(reader, null);
while (try iter.next()) |file| {
...
}
2024-01-13 19:37:33 -07:00
Igor Anić
e21a12e56b tar: use @embedFile in tests
Like in other tests which uses testdata files (compress). That enables
wasi testing also, was failing because file system operations in tests.
2024-01-13 19:37:33 -07:00
Igor Anić
76fe1f53d5 tar: fix tests on 32-bit platforms 2024-01-13 19:37:33 -07:00
Igor Anić
a75fd4ff15 tar: move test cases to std/tar/testdata
Create std/tar/test.zig for test which uses cases from testdata.
2024-01-13 19:37:33 -07:00