X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Ftar.c;h=bb0abfe1d18abe039f5aeb13ddded4a324721c7c;hb=ddb0f96f0004f26f621aba88ae41c70a4c6070fe;hp=a5b1393f4433ca7a8d26ead5980b816e7f0b555f;hpb=82c746410d910c0884fd9f42f687aa6d3daf8f7e;p=chaz%2Ftar diff --git a/src/tar.c b/src/tar.c index a5b1393..bb0abfe 100644 --- a/src/tar.c +++ b/src/tar.c @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include @@ -230,6 +230,7 @@ enum SHOW_OMITTED_DIRS_OPTION, STRIP_COMPONENTS_OPTION, SUFFIX_OPTION, + TEST_LABEL_OPTION, TO_COMMAND_OPTION, TOTALS_OPTION, UNQUOTE_OPTION, @@ -311,6 +312,9 @@ static struct argp_option options[] = { N_("process only the NUMBERth occurrence of each file in the archive. This option is valid only in conjunction with one of the subcommands --delete, --diff, --extract or --list and when a list of files is given either on the command line or via -T option. NUMBER defaults to 1."), 21 }, {"seek", 'n', NULL, 0, N_("archive is seekable"), 21 }, + {"test-label", TEST_LABEL_OPTION, NULL, 0, + N_("List volume label and exit"), 21 }, + {NULL, 0, NULL, 0, N_("Overwrite control:"), 30}, @@ -634,14 +638,24 @@ for complete list of authors.\n")); " GNU General Public License for more details.\n" "\n" " You should have received a copy of the GNU General Public License\n" - " along with GNU tar; if not, write to the Free Software\n" - " Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n\n")); + " along with GNU tar; if not, write to the Free Software Foundation,\n" + " Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\n\n")); exit (0); } static volatile int _argp_hang; -static bool +enum read_file_list_state /* Result of reading file name from the list file */ + { + file_list_success, /* OK, name read successfully */ + file_list_end, /* End of list file */ + file_list_zero /* Zero separator encountered where it should not */ + }; + +/* Read from FP a sequence of characters up to FILENAME_TERMINATOR and put them + into STK. + */ +static enum read_file_list_state read_name_from_file (FILE *fp, struct obstack *stk) { int c; @@ -650,14 +664,18 @@ read_name_from_file (FILE *fp, struct obstack *stk) for (c = getc (fp); c != EOF && c != filename_terminator; c = getc (fp)) { if (c == 0) - FATAL_ERROR((0, 0, N_("file name contains null character"))); + { + /* We have read a zero separator. The file possibly is zero-separated */ + /* FATAL_ERROR((0, 0, N_("file name contains null character"))); */ + return file_list_zero; + } obstack_1grow (stk, c); counter++; } obstack_1grow (stk, 0); - return !(counter == 0 && c == EOF); + return (counter == 0 && c == EOF) ? file_list_end : file_list_success; } @@ -706,6 +724,7 @@ update_argv (const char *filename, struct argp_state *state) char **new_argv; size_t new_argc; bool is_stdin = false; + enum read_file_list_state read_state; if (!strcmp (filename, "-")) { @@ -720,9 +739,33 @@ update_argv (const char *filename, struct argp_state *state) open_fatal (filename); } - while (read_name_from_file (fp, &argv_stk)) + while ((read_state = read_name_from_file (fp, &argv_stk)) == file_list_success) count++; + if (read_state == file_list_zero) + { + size_t size; + + WARN ((0, 0, N_("%s: file name read contains nul character"), + quotearg_colon (filename))); + + /* Prepare new stack contents */ + size = obstack_object_size (&argv_stk); + p = obstack_finish (&argv_stk); + for (; size > 0; size--, p++) + if (*p) + obstack_1grow (&argv_stk, *p); + else + obstack_1grow (&argv_stk, '\n'); + obstack_1grow (&argv_stk, 0); + count = 1; + + /* Read rest of files using new filename terminator */ + filename_terminator = 0; + while (read_name_from_file (fp, &argv_stk) == file_list_success) + count++; + } + if (!is_stdin) fclose (fp); @@ -934,15 +977,14 @@ parse_opt (int key, char *arg, struct argp_state *state) stat_error (arg); USAGE_ERROR ((0, 0, _("Date sample file not found"))); } - newer_mtime_option.tv_sec = st.st_mtime; - newer_mtime_option.tv_nsec = TIMESPEC_NS (st.st_mtim); + newer_mtime_option = get_stat_mtime (&st); } else { if (! get_date (&newer_mtime_option, arg, NULL)) { WARN ((0, 0, _("Substituting %s for unknown date format %s"), - tartime (newer_mtime_option.tv_sec), quote (arg))); + tartime (newer_mtime_option, false), quote (arg))); newer_mtime_option.tv_nsec = 0; } else @@ -998,6 +1040,11 @@ parse_opt (int key, char *arg, struct argp_state *state) verbose_option++; break; + case TEST_LABEL_OPTION: + set_subcommand_option (LIST_SUBCOMMAND); + test_label_option = true; + break; + case 'T': update_argv (arg, state); /* Indicate we've been given -T option. This is for backward @@ -1724,7 +1771,15 @@ decode_options (int argc, char **argv) if (recursive_unlink_option) old_files_option = UNLINK_FIRST_OLD_FILES; - if (utc_option) + + if (test_label_option) + { + /* --test-label is silent if the user has specified the label name to + compare against. */ + if (args.input_files == 0) + verbose_option++; + } + else if (utc_option) verbose_option = 2; /* Forbid using -c with no input files whatsoever. Check that `-f -', @@ -1780,16 +1835,10 @@ decode_options (int argc, char **argv) if (verbose_option && args.textual_date_option) { - /* FIXME: tartime should support nanoseconds, too, so that this - comparison doesn't complain about lost nanoseconds. */ - char const *treated_as = tartime (newer_mtime_option.tv_sec); + char const *treated_as = tartime (newer_mtime_option, true); if (strcmp (args.textual_date_option, treated_as) != 0) - WARN ((0, 0, - ngettext ("Treating date `%s' as %s + %ld nanosecond", - "Treating date `%s' as %s + %ld nanoseconds", - newer_mtime_option.tv_nsec), - args.textual_date_option, treated_as, - newer_mtime_option.tv_nsec)); + WARN ((0, 0, _("Treating date `%s' as %s"), + args.textual_date_option, treated_as)); } }