diff options
author | Elliott Hughes <enh@google.com> | 2020-03-23 18:32:04 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-03-23 20:46:49 -0500 |
commit | 729f1de79c7c24745716f6781457fd46b58c456d (patch) | |
tree | eddd59d5c446415d2c244f9f38418b1e5f8cf91d | |
parent | 5a6d1746baacb40e2a3f094af50dbe9871afa3cf (diff) | |
download | toybox-729f1de79c7c24745716f6781457fd46b58c456d.tar.gz |
tar: implement --absolute-names.
Used by the Linux kernel build when copying kernel headers to
kernel-headers.tar.gz.
Bug: http://b/152244851
-rw-r--r-- | tests/tar.test | 3 | ||||
-rw-r--r-- | toys/posix/tar.c | 6 |
2 files changed, 6 insertions, 3 deletions
diff --git a/tests/tar.test b/tests/tar.test index 985cea5f..523faa67 100644 --- a/tests/tar.test +++ b/tests/tar.test @@ -148,6 +148,9 @@ testing "pass broken absolute symlink" "$TAR dir/linkabsbrok | LST" \ testing "pass /dev/null" \ "tar c --mtime @0 /dev/null 2>/dev/null | LST" \ "crw-rw-rw- root/root 1,3 1970-01-01 00:00 dev/null\n" "" "" +testing "--absolute-names" \ + "tar c --mtime @0 --absolute-names /dev/null 2>/dev/null | LST" \ + "crw-rw-rw- root/root 1,3 1970-01-01 00:00 /dev/null\n" "" "" # compression types testing "autodetect gzip" 'LST -f "$FILES"/tar/tar.tgz' \ 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] == '/') { |