diff options
author | Rob Landley <rob@landley.net> | 2019-05-25 18:53:41 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-05-25 18:53:41 -0500 |
commit | cf624717b45049b3d394aeeda85a3ee9b89388af (patch) | |
tree | 2fbafbc7cf1a1a981cd37ccee0de3efa3188d5d0 /toys | |
parent | e99f7467524878e3f523241061fec899aefcf683 (diff) | |
download | toybox-cf624717b45049b3d394aeeda85a3ee9b89388af.tar.gz |
Toybox doesn't provide bzip2 or xz compression side (and the roadmap has it as
out of scope), but the AOSP build airlock doesn't provide bzcat and friends.
So tar needs to be able to use both: check for *zcat first, and fall back to
"compressor -d" if it's not there.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/posix/tar.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/toys/posix/tar.c b/toys/posix/tar.c index 16b528fa..dec3fa5f 100644 --- a/toys/posix/tar.c +++ b/toys/posix/tar.c @@ -786,14 +786,10 @@ static void do_XT(char **pline, long len) if (pline) trim2list(TT.X ? &TT.excl : &TT.incl, *pline); } -static char *compression_tool() -{ - return FLAG(z) ? "gzip" : (FLAG(J) ? "xz" : "bzip2"); -} - void tar_main(void) { - char *s, **args = toys.optargs; + char *s, **args = toys.optargs, + *archiver = FLAG(z) ? "gzip" : (FLAG(J) ? "xz" : "bzip2"); int len = 0; // Needed when extracting to command @@ -830,7 +826,7 @@ void tar_main(void) TT.cwd = xabspath(s = xgetcwd(), 1); free(s); - // Remember archive inode + // Remember archive inode so we don't overwrite it or add it to itself { struct stat st; @@ -862,8 +858,13 @@ void tar_main(void) if (FLAG(j)||FLAG(z)||FLAG(J)) { int pipefd[2] = {hdr ? -1 : TT.fd, -1}, i, pid; + struct string_list *zcat = find_in_path(getenv("PATH"), + FLAG(j) ? "bzcat" : FLAG(J) ? "xz" : "zcat"); - xpopen_both((char *[]){compression_tool(), "-dc", NULL}, pipefd); + // Toybox provides more decompressors than compressors, so try them first + xpopen_both(zcat ? (char *[]){zcat->str, 0} : + (char *[]){archiver, "-dc", 0}, pipefd); + if (CFG_TOYBOX_FREE) llist_traverse(zcat, free); if (!hdr) { // If we could seek, child gzip inherited fd and we read its output @@ -932,7 +933,7 @@ void tar_main(void) if (FLAG(j)||FLAG(z)||FLAG(J)) { int pipefd[2] = {-1, TT.fd}; - xpopen_both((char *[]){compression_tool(), "-f", NULL}, pipefd); + xpopen_both((char *[]){archiver, "-f", 0}, pipefd); close(TT.fd); TT.fd = pipefd[0]; } |