From 26446d37f171fd22144f442f2faa0b5e4132cfa4 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 18 Oct 2022 04:14:41 -0500 Subject: [PATCH] Tar --xform extract side. Note: we accept --show-transformed as a NOP, it's always on. (Happy to disable it if someone can explain why?) --- tests/tar.test | 37 ++++++++++++++++++++++++++----------- toys/posix/tar.c | 1 + 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/tests/tar.test b/tests/tar.test index de6617c3..d7b738c4 100755 --- a/tests/tar.test +++ b/tests/tar.test @@ -30,11 +30,6 @@ function LST() tar tv "$@" | sed 's/[ \t][ \t]*/ /g' } -function LST2() -{ - LST | sed 's/^.* 23:31 //' -} - # Check that stored empty file is binary identical and decodes as expected. touch file testing "store file" "$TAR file | SUM 3" \ @@ -327,28 +322,30 @@ mkdir uno ln -s tres uno/dos touch uno/tres ln uno/tres uno/quatro +tt() { $TAR --no-recursion uno uno/{dos,tres,quatro} "$@" | \ + LST --show-transformed-names $XX | sed 's/^.* 23:31 //'; } testing 'xform S' \ - "$TAR --no-recursion uno uno/{dos,tres,quatro} --xform 's/uno/one/S;s/dos/two/S;s/tres/three/S;s/quatro/four/S' | LST2" \ + "tt --xform 's/uno/one/S;s/dos/two/S;s/tres/three/S;s/quatro/four/S'" \ "one/\none/two -> tres\none/three\none/four link to one/three\n" "" "" testing 'xform flags=rh starts with all disabled' \ - "$TAR --no-recursion uno uno/{dos,tres,quatro} --xform 's/uno/one/;flags=rh;s/dos/two/;s/tres/three/;s/quatro/four/' | LST2" \ + "tt --xform 's/uno/one/;flags=rh;s/dos/two/;s/tres/three/;s/quatro/four/'" \ "one/\none/two -> tres\none/three\none/four link to one/three\n" "" "" testing 'xform flags=rHhsS toggles' \ - "$TAR --no-recursion uno uno/{dos,tres,quatro} --xform 's/uno/one/;flags=rHhsS;s/dos/two/;s/tres/three/;s/quatro/four/' | LST2" \ + "tt --xform 's/uno/one/;flags=rHhsS;s/dos/two/;s/tres/three/;s/quatro/four/'"\ "one/\none/two -> tres\none/three\none/four link to one/three\n" "" "" testing 'xform flags= is not a delta from previous' \ - "$TAR --no-recursion uno uno/{dos,tres,quatro} --xform 'flags=s;flags=rh;s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/' | LST2" \ + "tt --xform 'flags=s;flags=rh;s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/'" \ "one/\none/two -> tres\none/three\none/four link to one/three\n" "" "" testing 'xform H' \ - "$TAR --no-recursion uno uno/{dos,tres,quatro} --xform 'flags=rsH;s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/' | LST2" \ + "tt --xform 'flags=rsH;s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/'" \ "one/\none/two -> three\none/three\none/four link to uno/tres\n" "" "" testing 'xform R' \ - "$TAR --no-recursion uno uno/{dos,tres,quatro} --xform 'flags=rshR;s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/' | LST2" \ + "tt --xform 'flags=rshR;s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/'" \ "uno/\nuno/dos -> three\nuno/tres\nuno/quatro link to one/three\n" "" "" testing "xform path" "$TAR one --xform=s@three/four/@zero@ | tar t | grep six" \ @@ -356,6 +353,24 @@ testing "xform path" "$TAR one --xform=s@three/four/@zero@ | tar t | grep six" \ testing "xform trailing slash special case" \ "$TAR --xform 's#^.+/##x' one/two/three/four/five | tar t" 'five/\nsix\n' '' '' + +# The quoting works because default IFS splits on whitepace not ; +testing "xform extract all" \ + "XX='--xform s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/' tt" \ + 'one/\none/two -> three\none/three\none/four link to one/three\n' '' '' + +testing 'xform extract S' \ + "XX='--xform s/uno/one/S;s/dos/two/S;s/tres/three/S;s/quatro/four/S' tt" \ + "one/\none/two -> tres\none/three\none/four link to one/three\n" "" "" + +testing 'xform extract H' \ + "XX='--xform flags=rs;s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/' tt"\ + "one/\none/two -> three\none/three\none/four link to uno/tres\n" "" "" + +testing 'xform extract R' \ + "XX='--xform flags=sh;s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/' tt"\ + "uno/\nuno/dos -> three\nuno/tres\nuno/quatro link to one/three\n" "" "" + rm -rf uno SKIP=0 rm -rf one diff --git a/toys/posix/tar.c b/toys/posix/tar.c index 44a3b3b9..6f080689 100644 --- a/toys/posix/tar.c +++ b/toys/posix/tar.c @@ -802,6 +802,7 @@ static void unpack_tar(char *first) free(TT.hdr.name); TT.hdr.name = name; } + if ((i = "\0hs"[stridx("12", tar.type)+1])) xform(&TT.hdr.link_target, i); for (i = 0; i