diff options
author | Elliott Hughes <enh@google.com> | 2019-04-29 15:53:50 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-05-01 13:04:44 -0500 |
commit | d97be5e94f46986903970d35b17682adc8554da0 (patch) | |
tree | d8fc29b3023e86b0afdb61fe6f4857afa8d858d1 /toys | |
parent | 333a8c6500981be6cd7391b32bd794a6d6ca91b3 (diff) | |
download | toybox-d97be5e94f46986903970d35b17682adc8554da0.tar.gz |
tar: use same tools for decompression as for compression.
This is what GNU tar does, so Android's build system jail allows
bzip2, gzip, and xz, but not bzcat, zcat, and xzcat.
Why the function? Because auto-detection works by setting toyflags, so
we need to make sure we test the flags late, so it's either two copies
of this or a function.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/posix/tar.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/toys/posix/tar.c b/toys/posix/tar.c index cfeedcba..c073bbe6 100644 --- a/toys/posix/tar.c +++ b/toys/posix/tar.c @@ -646,6 +646,11 @@ 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; @@ -658,7 +663,7 @@ void tar_main(void) if (!geteuid()) toys.optflags |= FLAG_p; if (TT.owner) TT.ouid = xgetuid(TT.owner); if (TT.group) TT.ggid = xgetgid(TT.group); - if (TT.mtime) xparsedate(TT.mtime, &TT.mtt, (void *)&s, 1); + if (TT.mtime) xparsedate(TT.mtime, &TT.mtt, (void *)&s, 1); // Collect file list. for (; TT.exclude; TT.exclude = TT.exclude->next) @@ -717,11 +722,8 @@ void tar_main(void) if (FLAG(j)||FLAG(z)||FLAG(J)) { int pipefd[2] = {hdr ? -1 : TT.fd, -1}, i, pid; - char *cmd[] = {"bzcat", 0}; - if (FLAG(J)) cmd[0] = "xzcat"; - else if FLAG(z) cmd[0]++; - xpopen_both(cmd, pipefd); + xpopen_both((char *[]){compression_tool(), "-dc", NULL}, pipefd); if (!hdr) { // If we could seek, child gzip inherited fd and we read its output @@ -790,8 +792,7 @@ void tar_main(void) if (FLAG(j)||FLAG(z)||FLAG(J)) { int pipefd[2] = {-1, TT.fd}; - xpopen_both((char *[]){FLAG(z)?"gzip":FLAG(J)?"xz":"bzip2", "-f", NULL}, - pipefd); + xpopen_both((char *[]){compression_tool(), "-f", NULL}, pipefd); close(TT.fd); TT.fd = pipefd[0]; } |