-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
implement strip_components option of std.tar in std.zip as per #20257 #20263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Would you mind taking a look, @marler8997? |
I'm questioning the utility of this particular API. I can see how a value of The current implementation of this doesn't seem to take into account what happens if/when you have the same filename underneath differing directories, and I imagine implementing this in a reasonable way (doesn't do something unexpected) could add a good amount of complexity as you'd then need to decide how to handle and distinguish between cases where you're extracting into an existing directory vs extracting files with conflicting names. I imagine applications would want to detect and assert an error if this happens instead, but this would then require tracking all files extracted (hard to do without an allocator). This also couples the result to an implementation detail, the order in which the extraction decides to create the files. The zig repo itself doesn't need this feature even though it does support stripping the root directory. It does so by instead allowing the "extractZip" function to return either the top-level directory, or a subdirectory if it detects there is only 1. This is a good general approach since you can't know if there is in fact a single top-level directory beforehand. An application that wants to remove the top-level directory beforehand would need to be limited to only supporting zip files that contain a single top-level directory which is a more niche, but still plausible. We could eliminate most of these decisions by simplifying the api into: /// Strips the single root directory of the zip file. Asserts error.ZipMultipleRoots if there is more than
/// one root directory.
strip_root_directory: bool, Furthermore, if there was such a niche case that wanted to do something more complicated, applications can already implement their own version of the small 13-line |
Thanks for having a look! I agree
I just commented yesterday on the std.tar single file tars fail. issue that there's not really a need for I'd say it makes more sense to align the options of |
Ping @marler8997 for thoughts on the above. |
I think any comments I have would just be rehashing what's already been said. To summarize, I'm in favor of a strip_root_directory option, I think a more general strip components feature creates a complex set of edge cases to account for and decisions to be made, and the implemention that results in the behavior you'd expect would likely rival the size of the entirety of std.zip and cause the function to now require an allocator. |
Implements feature request #20257 bringing the
strip_components
option ofstd.tar
over tostd.zip
As per std.tar it removes 0 or more path components from the beginning of the path.
This is mostly used with
0
or1
to handle the cases that all files are in the root of the archive vs all files are within a single directory in the root of the archive.Like
std.tar
it returnsBadFileName
if too many components are removed leaving the empty string as the filename.