Implement --one-top-level#2881
Conversation
It would be pointless to implement optional arguments before having any option that can actually accept them, so that's why I did this first. Putting archive_basename() into creation_set.c feels wrong, but that file has all the required static functions. I didn't test my CMakeLists.txt changes: I don't have it installed, and I've only added a single line. I assume it'll be fine... and if it's not, that's what CI is for :p
In the previous commit, `bsdtar -x --one-top-level` would only show the error after receiving some input. Not sure how I would test that.
|
|
A couple of questions:
|
|
I'll also point out that there is a simple way to achieve this already: Not every problem has to be solved within tar itself. There is some merit in supporting GNU tar options when those options are widely used by shell scripts. I've not personally seen folks rely on |
|
I fear GNU may have missed an opportunity to improve Otherwise, why call it that? Extracting an archive that contains a single top-level directory using "one-top-level" will produce a single top-level directory containing a single directory. That's just |
I think this mostly makes sense in the context of Our handling of
Yeah, that'd be a footgun if you switch from bsdtar to GNU tar. I could picture myself in a few years using
That wouldn't make sense if not for the unfortunate detail for ignoring existing directories (logically you can't chdir into a subdirectory of a newly created dir), so no. GNU tar doesn't seem to care about the order relative to -C.
I agree, I've dealt with this using some wrapper scripts up until now1. I thought about writing my own extraction utility using libarchive too, but at this point I think it's better to just contribute the features I want to bsdtar, instead of having two libarchive-based extraction utilities with somewhat overlapping option sets.
I mean, I think there's some merit to it. It's useful not to have to run mkdir separately, and the name inference is also nice. Footnotes
|



Closes #2354.
This also implements support for optional arguments in bsdtar, as splitting it into a separate PR wouldn't make sense.
I think it would be nice to have an additional option that aborts the extraction if the directory exists, but I haven't implemented that here (yet?). For me, the point of
--one-top-levelis not to mess with the files/directories I already have - so it's kinda annoying that, in this one specific case, tar will extract files into an existing directory anyways. Sadly, GNU tar made that mistake before us, so I had to copy it.