[Toybox] tar creating empty archive?

Hong, Yifan elsk at google.com
Thu Apr 17 12:28:45 PDT 2025


Hello Rob,

Is there a way to create an empty tar archive with toybox? I tried:

$ ./toybox tar czf foo.tar.gz -T /dev/null
tar: empty archive

It seems that this comes from from
https://github.com/gfto/toybox/blob/75ebbd1571c85a06c0f4767beb7c20a19068f0b6/toys/pending/tar.c#L763
.

Background The reason I ask is that I want to do this:

tar czf out.tar.gz -T filelist.txt

But filelist.txt could be empty and I expect it to create an empty archive.
If toybox can't create empty archive when -T is empty, I have to use the
following workaround instead (untested pseudocode):

if [ -s filelist.txt ]; then
    tar czf out.tar.gz -T filelist.txt
else
    gzip < /dev/null > out.tar.gz
fi

... which works, but it is not quite gracefully handled IMO.

As a reference, GNU tar 1.35 does the following:

# This fails
$ tar czf out.tar.gz
tar: Cowardly refusing to create an empty archive

# This succeeds
$ tar czf out.tar.gz -T /dev/null

-- 
Hong, Yifan <elsk at google.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20250417/b1e5b044/attachment.htm>


More information about the Toybox mailing list