From: Sergey Poznyakoff Date: Mon, 15 Jun 2020 18:10:46 +0000 (+0300) Subject: Make sure link counting works for file names supplied with -T X-Git-Tag: release_1_33~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63712973c77ede016d859760b18d272bd175fd8e;p=thirdparty%2Ftar.git 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. --- diff --git a/src/common.h b/src/common.h index 18f1415c..8f5de570 100644 --- a/src/common.h +++ b/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); diff --git a/src/create.c b/src/create.c index e47da889..8b6564e6 100644 --- a/src/create.c +++ b/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 (); diff --git a/src/names.c b/src/names.c index ebc396b6..fc9e3055 100644 --- a/src/names.c +++ b/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. */