]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Make sure link counting works for file names supplied with -T
authorSergey Poznyakoff <gray@gnu.org>
Mon, 15 Jun 2020 18:10:46 +0000 (21:10 +0300)
committerSergey Poznyakoff <gray@gnu.org>
Mon, 15 Jun 2020 18:10:46 +0000 (21:10 +0300)
* src/common.h (name_count): Remove extern.
(files_count): New enum.
(filename_args): New extern.
* src/names.c (name_count): Remove.
(files_count): New variable.
(name_add_name,name_add_file): Update filename_args.
* src/create.c (create_archive): Set trivial_link_count depending on
the filename_args.

src/common.h
src/create.c
src/names.c

index 18f1415c9eb80c4e9a35eae56f058b1be7609dec..8f5de570f75f7a4eca8becdf22ef56b70b58e634 100644 (file)
@@ -742,7 +742,21 @@ int set_file_atime (int fd, int parentfd, char const *file,
 
 /* Module names.c.  */
 
-extern size_t name_count;
+enum files_count
+  {
+    FILES_NONE,
+    FILES_ONE,
+    FILES_MANY
+  };
+extern enum files_count filename_args;
+
+/* Return true if there are file names in the list */
+static inline bool
+name_more_files (void)
+{
+  return filename_args != FILES_NONE;
+}
+
 extern struct name *gnu_list_name;
 
 void gid_to_gname (gid_t gid, char **gname);
index e47da889f53badec55e1099a0556cac7d7a1b459..8b6564e647b3eaf93062910891869efbf9adec49 100644 (file)
@@ -1348,7 +1348,7 @@ create_archive (void)
 {
   struct name const *p;
 
-  trivial_link_count = name_count <= 1 && ! dereference_option;
+  trivial_link_count = filename_args != FILES_MANY && ! dereference_option;
 
   open_archive (ACCESS_WRITE);
   buffer_write_global_xheader ();
index ebc396b6c90304eaf8d80853a9974d9be3c69475..fc9e3055b26fd290e57e3c8b80446982f6f46536 100644 (file)
@@ -651,8 +651,10 @@ struct name_elt        /* A name_array element. */
   } v;
 };
 
-static struct name_elt *name_head;/* store a list of names */
-size_t name_count;               /* how many of the entries are file names? */
+static struct name_elt *name_head; /* store a list of names */
+
+/* how many of the entries are file names? */
+enum files_count filename_args = FILES_NONE;
 
 static struct name_elt *
 name_elt_alloc (void)
@@ -784,13 +786,6 @@ name_list_advance (void)
     }
 }
 
-/* Return true if there are names or options in the list */
-bool
-name_more_files (void)
-{
-  return name_count > 0;
-}
-
 /* Add to name_array the file NAME with fnmatch options MATFLAGS */
 void
 name_add_name (const char *name)
@@ -799,7 +794,20 @@ name_add_name (const char *name)
 
   ep->type = NELT_NAME;
   ep->v.name = name;
-  name_count++;
+
+  switch (filename_args)
+    {
+    case FILES_NONE:
+      filename_args = FILES_ONE;
+      break;
+
+    case FILES_ONE:
+      filename_args = FILES_MANY;
+      break;
+
+    default:
+      break;
+    }
 }
 
 static void
@@ -829,7 +837,10 @@ name_add_file (const char *name)
   ep->v.file.name = name;
   ep->v.file.line = 0;
   ep->v.file.fp = NULL;
-  name_count++;
+
+  /* We don't know beforehand how many files are listed.
+     Assume more than one. */
+  filename_args = FILES_MANY;
 }
 \f
 /* Names from external name file.  */