From 75628938a801c51cc40a49f8bc593c8e8bc22f1f Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 14 Jul 2022 16:33:33 -0700 Subject: [PATCH] tar: implement --null. No --no-null because it requires new infrastructure, and doesn't (yet) have a user. --- tests/tar.test | 8 ++++++++ toys/posix/tar.c | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/tar.test b/tests/tar.test index eb75d2cd..84f99083 100755 --- a/tests/tar.test +++ b/tests/tar.test @@ -38,6 +38,14 @@ testing "create file" "$TAR file | SUM 3" \ testing "pass file" "$TAR file | LST" \ "-rw-rw-r-- root/root 0 2009-02-13 23:31 file\n" "" "" +touch file1 file2 +echo -e "file1\nfile2" > files-newline +testing "-T newline" "$TAR -T files-newline | LST" \ + "-rw-rw-r-- root/root 0 2009-02-13 23:31 file1\n-rw-rw-r-- root/root 0 2009-02-13 23:31 file2\n" "" "" +tr '\n' '\0' < files-newline > files-null +testing "-T null" "$TAR --null -T files-null | LST" \ + "-rw-rw-r-- root/root 0 2009-02-13 23:31 file1\n-rw-rw-r-- root/root 0 2009-02-13 23:31 file2\n" "" "" + # The kernel has two hardwired meaningful UIDs: 0 (root) and 65534 (nobody). # (Technically changeable via /proc/sys/*/overflowuid but nobody ever does) skipnot id nobody >/dev/null diff --git a/toys/posix/tar.c b/toys/posix/tar.c index 57e1e140..4ac10e75 100644 --- a/toys/posix/tar.c +++ b/toys/posix/tar.c @@ -16,8 +16,10 @@ * * Why --exclude pattern but no --include? tar cvzf a.tgz dir --include '*.txt' * + * No --no-null because the args infrastructure isn't ready. + * -USE_TAR(NEWTOY(tar, "&(show-transformed-names)(selinux)(restrict)(full-time)(no-recursion)(numeric-owner)(no-same-permissions)(overwrite)(exclude)*(mode):(mtime):(group):(owner):(to-command):~(strip-components)(strip)#~(transform)(xform)*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)*I(use-compress-program):C(directory):f(file):a[!txc][!jzJa]", TOYFLAG_USR|TOYFLAG_BIN)) +USE_TAR(NEWTOY(tar, "&(show-transformed-names)(selinux)(restrict)(full-time)(no-recursion)(null)(numeric-owner)(no-same-permissions)(overwrite)(exclude)*(mode):(mtime):(group):(owner):(to-command):~(strip-components)(strip)#~(transform)(xform)*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)*I(use-compress-program):C(directory):f(file):a[!txc][!jzJa]", TOYFLAG_USR|TOYFLAG_BIN)) config TAR bool "tar" @@ -40,6 +42,7 @@ config TAR --sparse Record sparse files --selinux Save/restore labels --restrict All under one dir --no-recursion Skip dir contents --numeric-owner Use numeric uid/gid, not user/group names + --null Filenames in -T FILE are null-separated, not newline --strip-components NUM Ignore first NUM directory components when extracting --xform=SED Modify filenames via SED expression (ala s/find/replace/g) -I PROG Filter through PROG to compress or PROG -d to decompress @@ -907,7 +910,8 @@ void tar_main(void) trim2list(&TT.excl, TT.exclude->arg); for (;TT.X; TT.X = TT.X->next) do_lines(xopenro(TT.X->arg), '\n', do_XT); for (args = toys.optargs; *args; args++) trim2list(&TT.incl, *args); - for (;TT.T; TT.T = TT.T->next) do_lines(xopenro(TT.T->arg), '\n', do_XT); + for (;TT.T; TT.T = TT.T->next) + do_lines(xopenro(TT.T->arg), FLAG(null) ? '\0' : '\n', do_XT); // If include file list empty, don't create empty archive if (FLAG(c)) { -- 2.39.2