[Toybox] alias tar="tar --restrict"
Rob Landley
rob at landley.net
Fri Apr 5 20:44:50 PDT 2019
I just added --restrict to require all the tarball's contents to extract under a
single directory, and the obvious way to use it is the same as ls --color, via
alias.
$ tar cz linux-4.20 l*.txt > ll.tgz
$ tar xvf ../ll.tgz --restrict
...
linux-4.20/net/x25/x25_link.c
linux-4.20/net/x25/x25_proc.c
linux-4.20/net/x25/sysctl_net_x25.c
l11.txt
tar: 'l11.txt' not under '/home/landley/toybox/toy3/tartest/sub/linux-4.20'
l1.txt
tar: 'l1.txt' not under '/home/landley/toybox/toy3/tartest/sub/linux-4.20'
l2.txt
tar: 'l2.txt' not under '/home/landley/toybox/toy3/tartest/sub/linux-4.20'
$
Except... tar xvzf not needing dash is because the first argument is treated
specially, and extra arguments from alias come first. Do you suppose that should
be the first _non-longopt_ argument, maybe?
Rob
P.S. I made it detect filenames ending in .tgz and such during compression if
you didn't specify a type. You can work around that via redirect like above
(hence no filename), but should there also be a command line --stoppit? I'm
leaning no because gunzip and bunzip2 renaming have similar "this is the
extension, it means something to me, deal with it", but I should probably ask
the question. (Extract ignores the filename and checks the signature. This one
can handle "cat blah.tgz | tar xv", the gnu/dammit one didn't bother to make
that work.)
P.P.S. The gnu/dammit --restrict is utterly useless, it disables the ! command
to spawn a subshell when prompting to change tapes. No really. They added this
in 2005. I reused it because as long as they already added a NOP it means you
can feed --restrict to both and it'll just work.
More information about the Toybox
mailing list