[Toybox] alias tar="tar --restrict"

Rob Landley rob at landley.net
Sun May 12 19:44:29 PDT 2019


On 4/11/19 5:29 PM, Rob Landley wrote:
> On 4/11/19 11:34 AM, enh wrote:
>> On Fri, Apr 5, 2019 at 8:44 PM Rob Landley <rob at landley.net> wrote:
>>>
>>> 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?
> 
> I guess I should assume that this is the case then?

I sat down and implemented it (attached if you're curious)  and then started
worrying about:

  $ tar --create vf
  tar: Refusing to write archive contents to terminal (missing -f option?)
  tar: Error is not recoverable: exiting now

And went "no, somebody's going to do that" so the rule can't be first non-short
opt it has to be first _opt_.

So I dug into the bash man page and although alias doesn't have a way to say
"put the arguments here", shell _functions" with "$@" do. So you can still go:

tar()
{
  command tar "$@" --restrict
}

Which means I don't need to modify toybox to make the new option usefully
applicable as an environment default. (Dunno if mksh can do that, but it's on
the toysh todo list.)

Rob

P.S. the attached patch wound up doing:

  if (0) {
label:
    stuff();
  }

And went "is that going to break a compiler?" (undead code elimination, that was
one of my test cases for my old tinycc for by the way) and I ran "make tests"
under both compilers and found out a lot of the utf8 tests are failing under
llvm/bionic that aren't failing under glibc and I should probably update my ndk
before trying to track them down (it's from September..). Pretty standard
programming session for me, really. I'm trying to close things down to cut a
release, so naturally I'm generating new todo items...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wheee.patch
Type: text/x-patch
Size: 1934 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20190512/c1cfd71c/attachment-0002.bin>


More information about the Toybox mailing list