From 8378c81b4471be8b94facc134fe83de660f365d2 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Thu, 9 Nov 2023 15:24:37 +0200 Subject: [PATCH] Refactor / cleanup rpm2archive entry fillup a bit Do all the entry fillup in the function intended for that, no functional changes intended. Drop the unnecessary nlink check from the unpacking: if there's content, it should unpacked. --- tools/rpm2archive.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/tools/rpm2archive.c b/tools/rpm2archive.c index d394236208..4e09167cff 100644 --- a/tools/rpm2archive.c +++ b/tools/rpm2archive.c @@ -35,7 +35,8 @@ static struct poptOption optionsTable[] = { POPT_TABLEEND }; -static void fill_archive_entry(struct archive_entry * entry, rpmfi fi) +static void fill_archive_entry(struct archive_entry * entry, rpmfi fi, + char **hardlink) { archive_entry_clear(entry); const char * dn = rpmfiDN(fi); @@ -56,6 +57,16 @@ static void fill_archive_entry(struct archive_entry * entry, rpmfi fi) if (S_ISLNK(sb.st_mode)) archive_entry_set_symlink(entry, rpmfiFLink(fi)); + + if (sb.st_nlink > 1) { + if (rpmfiArchiveHasContent(fi)) { + _free(*hardlink); + *hardlink = xstrdup(archive_entry_pathname(entry)); + } else { + archive_entry_set_hardlink(entry, *hardlink); + } + } + } static int write_file_content(struct archive * a, char * buf, rpmfi fi) @@ -209,19 +220,7 @@ static int process_package(rpmts ts, const char * filename) break; } - rpm_mode_t mode = rpmfiFMode(fi); - int nlink = rpmfiFNlink(fi); - - fill_archive_entry(entry, fi); - - if (nlink > 1) { - if (rpmfiArchiveHasContent(fi)) { - _free(hardlink); - hardlink = xstrdup(archive_entry_pathname(entry)); - } else { - archive_entry_set_hardlink(entry, hardlink); - } - } + fill_archive_entry(entry, fi, &hardlink); if (archive_write_header(a, entry) != ARCHIVE_OK) { if (archive_errno(a) == ERANGE) { @@ -236,7 +235,7 @@ static int process_package(rpmts ts, const char * filename) } } - if (S_ISREG(mode) && (nlink == 1 || rpmfiArchiveHasContent(fi))) { + if (S_ISREG(archive_entry_mode(entry)) && rpmfiArchiveHasContent(fi)) { if (write_file_content(a, buf, fi)) { rc = ARCHIVE_FAILED; break;