[Toybox] more tar madness

Rob Landley rob at landley.net
Sat Oct 8 01:11:45 PDT 2022


On 10/7/22 18:01, enh via Toybox wrote:
> continuing to be a moving target...
> 
> the kernel folks are about to start using tar --wildcards, which i also hadn't
> heard of.
> (https://android-review.googlesource.com/c/kernel/build/+/2241508/7..9/kleaf/impl/abi/extracted_symbols.bzl#73)

Oh joy.

> sounds like that might be a no-op though, asking for the default behavior?
> 
>        --wildcards
>               Use wildcards (default for exclusion).

No, the default behavior is --no-wildcards. Saying --wildcards tells tar to
expand them (when ordinarily the shell does it). I have no idea WHY you would
want tar to do this instead of the shell... for extract. Of course.

Let's see, what does this apply to...

$ tar tvz --wildcards -f 'toybox-0.8.[0].tar.gz'
tar (child): toybox-0.8.[0].tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

Not the archive name. Ok.

$ tar tvz --wildcards -f 'toybox-0.8.0.tar.gz' 'toybox-0.?.0/www/*.png'
-rw-rw-r-- root/root     48192 2019-02-08 20:15 toybox-0.8.0/www/toycans.png

And there it is.

$ tar tvz --wildcards -f 'toybox-0.8.0.tar.gz' 'toybox-0.?.0' | wc -l
523

And of course it's wildcard expansion with paths... I think man 3 fnmatch()
should handle all this? (I also have plumbing for it in toysh, but let's grab
the libc thing for the moment...)

Of course the OTHER question this re-raises is whether lib/args.c needs to know
about --no-thingy prefixes. I kinda want to add a "(potato)!" trailing
punctuation to say this --longopt can toggle on and off with --no-whatsis, except:

A) all the other trailing punctuation on options is about argument types, and
--wildcards doesn't take an argument,

B) changing that is surgery not just to lib/args.c but to scripts/mkflags.c,

Which says maybe it should be more like (!potato) to not be a magic special case
where trailing punctuation does NOT mean populate a GLOBALS() argument, except:

C) the existing no-thingy arguments treat the option as a normal positive option:

$ grep -o '(no-[^)]*)' toys/*/*.c
toys/other/nsenter.c:(no-fork)

Does not have an non-no version on debian:

$ nsenter --fork ls
nsenter: unrecognized option '--fork'
Try 'nsenter --help' for more information.

toys/other/pwgen.c:(no-capitalize)

-A is the short option for no-capitalize, -c is the short option for capitalize.

(In which case the existing syntax can cope, albeit verbosely, by having both
and doing [-Ac] at the end, the "switch off" grouping...)

toys/other/pwgen.c:(no-numerals)

-0 is short for no-numerals, -n is short for numerals.

toys/other/readlink.c:(no-symlinks)

That's actually realpath (although debian's readlink has --no-newline without a
corresponding --newline option.)

Hilariously, realpath --no-symlinks is the longopt version of -s and the
corresponding short option is -P which DOES NOT HAVE A LONGOPT.

$ realpath --symlinks hello
realpath: unrecognized option '--symlinks'
Try 'realpath --help' for more information.

toys/posix/chgrp.c:(no-dereference)

--no-dereference is longopt for -h, --dereference does not have a short opt.

toys/posix/cpio.c:(no-preserve-owner)

There's neither a --preserve-owner nor a short opt.

toys/posix/grep.c:(no-filename)

Oh goddess, the alternate this toggles is --with-filename. -h and -H short.

toys/posix/patch.c:(no-backup-if-mismatch)

Ok, a straight toggle: --backup-if-mismatch, --no-backup-if-mismatch, neither
has a short option, and toybox only implements the --no version so far.

toys/posix/tar.c:(no-recursion)

Has --no-recursion and --recursion, no short options.

toys/posix/tar.c:(no-same-permissions)

No short option for --no-same-permissions, --same-permissions is -p.

toys/posix/tar.c:(no-same-owner)

Has both versions, no short options.

Right. So half the time there's short options and I can use short option
grouping to turn them into toggles for each other, and half the time one or both
don't have a short option and I can't use that. And pretty much all the tar
cases are the latter type.

And in fact, no-same-permissions is there in the option string but not actually
wired up to anything that I can tell? (Second one of those I've encountered this
week, I need to make some kind of checker for that. Although REALLY what I need
to do is fill out the test suite with systematic regression tests that test
every command line option, and have a checker for THAT...)

Ok, that needs design work, some long walks, and caffeine. Grrr... four cases:
(potato!xy) (potato!_y) or (potato!x_) (potato!) except I refuse to have a
second source of short options so you still need them declare in the normal way
and this is just like [-xy] grouping so really what you'd do is have the no-
version occur FIRST and then put the longopt on the yes version with an optional
(potato!x) refer back to previous short option that's our no version... except
the order requirement doesn't work when the other one's a bare longopt, but I
guess I could have (no-potato!x) and it can be a forward reference that this
short option toggles us... Grrr. Bit more magic than I like, more pacing...

In the short term you need --wildcard hooked up to fnmatch(3).

> also, allegedly (by which i only mean "i haven't confirmed myself") that new use
> of --xform gets you a "bad xform" with toybox tar...
> 
> tar --directory={intermediates_dir} --wildcards --xform='s#^.+/##x' -xf
> {base_modules_archive} '*.ko'

Because I haven't added the xform flag support yet, and adding 'x' is part of
that. (People keep sending me bug reports...)

Rob


More information about the Toybox mailing list