From 729f1de79c7c24745716f6781457fd46b58c456d Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 23 Mar 2020 18:32:04 -0700 Subject: tar: implement --absolute-names. Used by the Linux kernel build when copying kernel headers to kernel-headers.tar.gz. Bug: http://b/152244851 --- toys/posix/tar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'toys/posix') diff --git a/toys/posix/tar.c b/toys/posix/tar.c index 16e4e49c..9642fbe6 100644 --- a/toys/posix/tar.c +++ b/toys/posix/tar.c @@ -17,7 +17,7 @@ * Why --exclude pattern but no --include? tar cvzf a.tgz dir --include '*.txt' * -USE_TAR(NEWTOY(tar, "&(restrict)(full-time)(no-recursion)(numeric-owner)(no-same-permissions)(overwrite)(exclude)*(mode):(mtime):(group):(owner):(to-command):o(no-same-owner)p(same-permissions)k(keep-old)c(create)|h(dereference)x(extract)|t(list)|v(verbose)J(xz)j(bzip2)z(gzip)S(sparse)O(to-stdout)m(touch)X(exclude-from)*T(files-from)*C(directory):f(file):a[!txc][!jzJa]", TOYFLAG_USR|TOYFLAG_BIN)) +USE_TAR(NEWTOY(tar, "&(restrict)(full-time)(no-recursion)(numeric-owner)(no-same-permissions)(overwrite)(exclude)*(mode):(mtime):(group):(owner):(to-command):o(no-same-owner)p(same-permissions)k(keep-old)c(create)|h(dereference)x(extract)|t(list)|v(verbose)J(xz)j(bzip2)z(gzip)S(sparse)O(to-stdout)P(absolute-names)m(touch)X(exclude-from)*T(files-from)*C(directory):f(file):a[!txc][!jzJa]", TOYFLAG_USR|TOYFLAG_BIN)) config TAR bool "tar" @@ -189,7 +189,7 @@ static int add_to_tar(struct dirtree *node) } i = 1; - name = dirtree_path(node, &i); + name = hname = dirtree_path(node, &i); // exclusion defaults to --no-anchored and --wildcards-match-slash for (lnk = name; *lnk;) { @@ -202,7 +202,7 @@ static int add_to_tar(struct dirtree *node) if (S_ISDIR(st->st_mode) && name[i-1] != '/') strcat(name, "/"); // remove leading / and any .. entries from saved name - for (hname = name; *hname == '/'; hname++); + if (!FLAG(P)) while (*hname == '/') hname++; for (lnk = hname;;) { if (!(lnk = strstr(lnk, ".."))) break; if (lnk == hname || lnk[-1] == '/') { -- cgit v1.2.3