Fix uid, gid and nlinks not getting populated by rpm2archive

Take advantage of rpmfiStat() and archive_entry_copy_stat() which
handle most of the dirty work here. Hardlink sizes are special because
in archives, the file size is 0 except for the one with the content,
but otherwise of course hardlinked files have sizes as usual.
This commit is contained in:
Panu Matilainen 2023-11-09 13:45:14 +02:00
parent fa1fbe95ed
commit b86f6ad4f0
1 changed files with 5 additions and 6 deletions

View File

@ -35,22 +35,21 @@ static void fill_archive_entry(struct archive_entry * entry, rpmfi fi)
archive_entry_clear(entry);
const char * dn = rpmfiDN(fi);
if (!strcmp(dn, "")) dn = "/";
struct stat sb;
char * filename = rstrscat(NULL, ".", dn, rpmfiBN(fi), NULL);
archive_entry_copy_pathname(entry, filename);
_free(filename);
rpmfiStat(fi, 0, &sb);
archive_entry_copy_stat(entry, &sb);
/* hardlink sizes are special, see rpmfiStat() */
archive_entry_set_size(entry, rpmfiFSize(fi));
rpm_mode_t mode = rpmfiFMode(fi);
archive_entry_set_filetype(entry, mode & S_IFMT);
archive_entry_set_perm(entry, mode);
archive_entry_set_uname(entry, rpmfiFUser(fi));
archive_entry_set_gname(entry, rpmfiFGroup(fi));
archive_entry_set_rdev(entry, rpmfiFRdev(fi));
archive_entry_set_mtime(entry, rpmfiFMtime(fi), 0);
if (S_ISLNK(mode))
if (S_ISLNK(sb.st_mode))
archive_entry_set_symlink(entry, rpmfiFLink(fi));
}