aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/tar.test3
-rw-r--r--toys/posix/tar.c6
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] == '/') {