diff --git a/usr.bin/tar/read.c b/usr.bin/tar/read.c index c66106093e1a..35cea89a95a2 100644 --- a/usr.bin/tar/read.c +++ b/usr.bin/tar/read.c @@ -210,22 +210,17 @@ read_archive(struct bsdtar *bsdtar, char mode) if (excluded(bsdtar, archive_entry_pathname(entry))) continue; /* Excluded by a pattern test. */ - /* - * Modify the pathname as requested by the user. We - * do this for -t as well to give users a way to - * preview the effects of their rewrites. We also do - * this before extraction security checks (including - * leading '/' removal). Note that some rewrite - * failures prevent extraction. - */ - if (edit_pathname(bsdtar, entry)) - continue; /* Excluded by a rewrite failure. */ - if (mode == 't') { /* Perversely, gtar uses -O to mean "send to stderr" * when used with -t. */ out = bsdtar->option_stdout ? stderr : stdout; + /* + * TODO: Provide some reasonable way to + * preview rewrites. gtar always displays + * the unedited path in -t output, which means + * you cannot easily preview rewrites. + */ if (bsdtar->verbose < 2) safe_fprintf(out, "%s", archive_entry_pathname(entry)); @@ -252,6 +247,10 @@ read_archive(struct bsdtar *bsdtar, char mode) } fprintf(out, "\n"); } else { + /* Note: some rewrite failures prevent extraction. */ + if (edit_pathname(bsdtar, entry)) + continue; /* Excluded by a rewrite failure. */ + if (bsdtar->option_interactive && !yes("extract '%s'", archive_entry_pathname(entry))) continue; diff --git a/usr.bin/tar/test/test_patterns.c b/usr.bin/tar/test/test_patterns.c index a90d711039ce..575e8a411232 100644 --- a/usr.bin/tar/test/test_patterns.c +++ b/usr.bin/tar/test/test_patterns.c @@ -30,7 +30,6 @@ DEFINE_TEST(test_patterns) int fd, r; const char *reffile2 = "test_patterns_2.tgz"; const char *reffile2_out = "test_patterns_2.tgz.out"; - const char *reffile2_err = "test_patterns_2.tgz.err"; /* * Test basic command-line pattern handling. @@ -56,13 +55,12 @@ DEFINE_TEST(test_patterns) */ extract_reference_file(reffile2); extract_reference_file(reffile2_out); - extract_reference_file(reffile2_err); r = systemf("%s tf %s /tmp/foo/bar > tar2a.out 2> tar2a.err", testprog, reffile2); assertEqualInt(r, 0); assertEqualFile("tar2a.out", reffile2_out); - assertEqualFile("tar2a.err", reffile2_err); + assertEmptyFile("tar2a.err"); /* * diff --git a/usr.bin/tar/test/test_patterns_2.tgz.err.uu b/usr.bin/tar/test/test_patterns_2.tgz.err.uu deleted file mode 100644 index cb0593087d31..000000000000 --- a/usr.bin/tar/test/test_patterns_2.tgz.err.uu +++ /dev/null @@ -1,6 +0,0 @@ -$FreeBSD$ -begin 644 test_patterns_2.tgz.err -M8G-D=&%R.B!296UO=FEN9R!L96%D:6YG("@H` +?+W1M<"]F;V\O8F%R+PHO=&UP+V9O;R]B87(O8F%Z"@`` ` end