Skip to content

Commit

Permalink
Give an error message for missing tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ffesti committed Nov 30, 2024
1 parent 8d47c69 commit 5e3db70
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/rpmte.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,15 @@ static int addTE(rpmte p, Header h, fnpyKey key, rpmRelocation * relocs)
p->release = headerGetAsString(h, RPMTAG_RELEASE);

/* name, version and release are required in all packages */
if (p->name == NULL || p->version == NULL || p->release == NULL)
goto exit;
for (auto [value, name] : std::vector<std::pair<char *, std::string>>
{{p->name, "name"},
{p->version, "version"},
{p->release, "release"}}) {
if (value == NULL) {
rpmlog(RPMLOG_ERR, _("Package is missing %s\n"), name.c_str());
goto exit;
}
}

p->epoch = headerGetAsString(h, RPMTAG_EPOCH);

Expand All @@ -163,6 +170,10 @@ static int addTE(rpmte p, Header h, fnpyKey key, rpmRelocation * relocs)
if (p->type == TR_REMOVED && rstreq(p->name, "gpg-pubkey")) {
rpmlog(RPMLOG_WARNING, "Erasing gpg-pubkey packages is deprecated! Use rpmkeys.\n");
} else {
if (p->arch == NULL)
rpmlog(RPMLOG_ERR, _("Package is missing %s\n"), "arch");
if (p->os == NULL)
rpmlog(RPMLOG_ERR, _("Package is missing %s\n"), "os");
goto exit;
}
}
Expand Down
25 changes: 25 additions & 0 deletions tests/rpmpython.at
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,31 @@ for e in ts:
[adding upgrade to transaction failed]
)

RPMPY_TEST([add bogus package to transaction 3],[

for tag in ["os", "arch", "name", "version", "release"]:
h = ts.hdrFromFdno('${RPMDATA}/RPMS/hello-1.0-1.ppc64.rpm')
del h[tag]
try:
ts.addInstall(h, 'foo', 'u')
except rpm.error as err:
myprint(err)
for e in ts:
myprint(e.NEVRA())
],
[adding upgrade to transaction failed
adding upgrade to transaction failed
adding upgrade to transaction failed
adding upgrade to transaction failed
adding upgrade to transaction failed
],
[error: Package is missing os
error: Package is missing arch
error: Package is missing name
error: Package is missing version
error: Package is missing release
])

RPMPY_TEST([transaction element userdata],[
mydata = { 'foo': 'bar', 'capstest': 'lock' }
ts.addInstall('${RPMDATA}/RPMS/foo-1.0-1.noarch.rpm', 'u')
Expand Down

0 comments on commit 5e3db70

Please sign in to comment.