]> Dogcows Code - chaz/tar/blobdiff - src/tar.c
* src/tar.c (NS_PRECISION_FORMAT_MASK): New macro.
[chaz/tar] / src / tar.c
index fcd4d52a5e4e428080c9b6bb21f0e8fe71a25de2..7736993cfe956d39326b3bdf39409fa97731bbd9 100644 (file)
--- a/src/tar.c
+++ b/src/tar.c
@@ -162,7 +162,7 @@ archive_format_string (enum archive_format fmt)
 static void
 assert_format(unsigned fmt_mask)
 {
-  if ((FORMAT_MASK(archive_format) & fmt_mask) == 0)
+  if ((FORMAT_MASK (archive_format) & fmt_mask) == 0)
     USAGE_ERROR ((0, 0,
                  _("GNU features wanted on incompatible archive format")));
 }
@@ -228,8 +228,10 @@ enum
   SAME_OWNER_OPTION,
   SHOW_DEFAULTS_OPTION,
   SHOW_OMITTED_DIRS_OPTION,
+  SHOW_STORED_NAMES_OPTION,
   STRIP_COMPONENTS_OPTION,
   SUFFIX_OPTION,
+  TEST_LABEL_OPTION,
   TO_COMMAND_OPTION,
   TOTALS_OPTION,
   UNQUOTE_OPTION,
@@ -295,6 +297,8 @@ static struct argp_option options[] = {
   {"concatenate", 0, 0, OPTION_ALIAS, NULL, 10},
   {"delete", DELETE_OPTION, 0, 0,
    N_("delete from the archive (not on mag tapes!)"), 10 },
+  {"test-label", TEST_LABEL_OPTION, NULL, 0,
+   N_("Test archive volume label and exit"), 10 },
 
   {NULL, 0, NULL, 0,
    N_("Operation modifiers:"), 20},
@@ -550,6 +554,9 @@ static struct argp_option options[] = {
    N_("Show tar defaults"), 102 },
   {"show-omitted-dirs", SHOW_OMITTED_DIRS_OPTION, 0, 0,
    N_("When listing or extracting, list each directory that does not match search criteria"), 102 },
+  {"show-stored-names", SHOW_STORED_NAMES_OPTION, 0, 0,
+   N_("When creating archive in verbose mode, list member names as stored in the archive"),
+   102 },
 
   {NULL, 0, NULL, 0,
    N_("Compatibility options:"), 110 },
@@ -641,7 +648,17 @@ for complete list of authors.\n"));
 
 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 +667,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;
 }
 
 \f
@@ -706,6 +727,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 +742,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 +980,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 +1043,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
@@ -1270,6 +1320,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
       show_omitted_dirs_option = true;
       break;
 
+    case SHOW_STORED_NAMES_OPTION:
+      show_stored_names_option = true;
+      break;
+
     case SUFFIX_OPTION:
       backup_option = true;
       args->backup_suffix_string = arg;
@@ -1618,7 +1672,12 @@ decode_options (int argc, char **argv)
                   | FORMAT_MASK (GNU_FORMAT));
 
 
-  if (incremental_option || multi_volume_option)
+  if (incremental_option)
+    assert_format (FORMAT_MASK (OLDGNU_FORMAT)
+                  | FORMAT_MASK (GNU_FORMAT)
+                  | FORMAT_MASK (POSIX_FORMAT));
+
+  if (multi_volume_option)
     assert_format (FORMAT_MASK (OLDGNU_FORMAT) | FORMAT_MASK (GNU_FORMAT));
 
   if (sparse_option)
@@ -1705,8 +1764,11 @@ decode_options (int argc, char **argv)
     {
       if (multi_volume_option)
        USAGE_ERROR ((0, 0, _("Cannot use multi-volume compressed archives")));
-      if (subcommand_option == UPDATE_SUBCOMMAND)
+      if (subcommand_option == UPDATE_SUBCOMMAND
+         || subcommand_option == APPEND_SUBCOMMAND)
        USAGE_ERROR ((0, 0, _("Cannot update compressed archives")));
+      if (subcommand_option == CAT_SUBCOMMAND)
+       USAGE_ERROR ((0, 0, _("Cannot concatenate compressed archives")));
     }
 
   /* It is no harm to use --pax-option on non-pax archives in archive
@@ -1724,7 +1786,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 +1850,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));
     }
 }
 
@@ -1914,5 +1978,20 @@ tar_stat_destroy (struct tar_stat_info *st)
   free (st->uname);
   free (st->gname);
   free (st->sparse_map);
+  free (st->dumpdir);
   memset (st, 0, sizeof (*st));
 }
+
+/* Format mask for all available formats that support nanosecond
+   timestamp resolution. */
+#define NS_PRECISION_FORMAT_MASK FORMAT_MASK (POSIX_FORMAT)
+
+/* Same as timespec_cmp, but ignore nanoseconds if current archive
+   format does not provide sufficient resolution.  */
+int
+tar_timespec_cmp (struct timespec a, struct timespec b)
+{
+  if (!(FORMAT_MASK (current_format) & NS_PRECISION_FORMAT_MASK))
+    a.tv_nsec = b.tv_nsec = 0;
+  return timespec_cmp (a, b);
+}
This page took 0.02569 seconds and 4 git commands to generate.