Skip to content

Commit

Permalink
Refactor / cleanup rpm2archive entry fillup a bit
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pmatilai committed Nov 9, 2023
1 parent 6773676 commit 8378c81
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions tools/rpm2archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 8378c81

Please sign in to comment.