瀏覽代碼

Make sure link counting works for file names supplied with -T

* 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.
Sergey Poznyakoff 4 年之前
父節點
當前提交
63712973c7
共有 3 個文件被更改,包括 38 次插入13 次删除
  1. 15 1
      src/common.h
  2. 1 1
      src/create.c
  3. 22 11
      src/names.c

+ 15 - 1
src/common.h

@@ -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);

+ 1 - 1
src/create.c

@@ -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 ();

+ 22 - 11
src/names.c

@@ -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;
 }
 
 /* Names from external name file.  */