--numeric-owner now affects private headers too

Problem reported by Daniel Peebles in:
http://lists.gnu.org/archive/html/bug-tar/2017-04/msg00004.html
* NEWS: Document this.
* src/create.c (write_gnu_long_link): If --numeric-owner,
leave the user and group empty in a private header.  Cache the
names for 0.
This commit is contained in:
Paul Eggert
2017-04-06 18:16:51 -07:00
parent d06126f814
commit da8d0659a6
2 changed files with 28 additions and 21 deletions

View File

@@ -202,8 +202,8 @@ to_base256 (int negative, uintmax_t value, char *where, size_t size)
#define MODE_TO_CHARS(val, where) mode_to_chars (val, where, sizeof (where))
#define UID_TO_CHARS(val, where) uid_to_chars (val, where, sizeof (where))
#define UNAME_TO_CHARS(name,buf) string_to_chars (name, buf, sizeof(buf))
#define GNAME_TO_CHARS(name,buf) string_to_chars (name, buf, sizeof(buf))
#define UNAME_TO_CHARS(name, buf) string_to_chars (name, buf, sizeof (buf))
#define GNAME_TO_CHARS(name, buf) string_to_chars (name, buf, sizeof (buf))
static bool
to_chars (int negative, uintmax_t value, size_t valsize,
@@ -542,15 +542,19 @@ write_gnu_long_link (struct tar_stat_info *st, const char *p, char type)
size_t size = strlen (p) + 1;
size_t bufsize;
union block *header;
char *tmpname;
header = start_private_header ("././@LongLink", size, 0);
uid_to_uname (0, &tmpname);
UNAME_TO_CHARS (tmpname, header->header.uname);
free (tmpname);
gid_to_gname (0, &tmpname);
GNAME_TO_CHARS (tmpname, header->header.gname);
free (tmpname);
if (! numeric_owner_option)
{
static char *uname, *gname;
if (!uname)
{
uid_to_uname (0, &uname);
gid_to_gname (0, &gname);
}
UNAME_TO_CHARS (uname, header->header.uname);
GNAME_TO_CHARS (gname, header->header.gname);
}
strcpy (header->buffer + offsetof (struct posix_header, magic),
OLDGNU_MAGIC);
@@ -743,7 +747,7 @@ start_header (struct tar_stat_info *st)
union block *header;
char const *uname = NULL;
char const *gname = NULL;
header = write_header_name (st);
if (!header)
return NULL;
@@ -830,11 +834,11 @@ start_header (struct tar_stat_info *st)
case USE_FILE_MTIME:
mtime = st->mtime;
break;
case FORCE_MTIME:
mtime = mtime_option;
break;
case CLAMP_MTIME:
mtime = timespec_cmp (st->mtime, mtime_option) > 0
? mtime_option : st->mtime;