From d97be5e94f46986903970d35b17682adc8554da0 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 29 Apr 2019 15:53:50 -0700 Subject: 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. --- toys/posix/tar.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'toys') 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]; } -- cgit v1.2.3