summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2020-12-02 12:19:15 +0200
committerPanu Matilainen <pmatilai@redhat.com>2020-12-10 13:28:07 +0200
commitedec916357541630b4deb9726b060b88778c64de (patch)
tree8400e971c60fb6d586a449c31505cd194c65a39c
parent768ecc02b22060f32402e9dc224d2ef578d0fb28 (diff)
downloadrpm-edec916357541630b4deb9726b060b88778c64de.tar.gz
Fix 4.16.0 regression causing invalid spec file name on rpmbuild -ts
Commit acf5e00281d73a2f8034091241c7b0e2ba00e383 cut a couple of corners too many, causing the temporary file name used to extract the spec from the tarball to end up in the src.rpm too. Revert back to creating %_specdir for tar builds, it might not be optimal but it's not exactly harmful either (%_sourcedir is different). The "truly correct" solutions get increasingly complicated for such a silly thing as this is. In addition to creating the %_specdir, we also need to rename the file to its proper name, simplify that code a bit while at it and add a test-case. Fixes: #1386 (cherry picked from commit dfffedb5ebe46e039c0313b3d2fb939dfc63efd6)
-rw-r--r--rpmbuild.c22
-rw-r--r--tests/rpmbuild.at15
2 files changed, 33 insertions, 4 deletions
diff --git a/rpmbuild.c b/rpmbuild.c
index ee3f69867..d02caa511 100644
--- a/rpmbuild.c
+++ b/rpmbuild.c
@@ -337,14 +337,16 @@ static int isSpecFile(const char * specfile)
static char * getTarSpec(const char *arg)
{
char *specFile = NULL;
+ char *specFinal = NULL;
const char **spec;
char tarbuf[BUFSIZ];
int gotspec = 0;
FD_t fd = NULL;
static const char *tryspec[] = { "Specfile", "\\*.spec", NULL };
- if (!(fd = rpmMkTempFile(NULL, &specFile)))
- goto exit;
+ specFile = rpmGetPath("%{_specdir}/", "rpm-spec.XXXXXX", NULL);
+ if (!(fd = rpmMkTemp(specFile)))
+ goto exit;
for (spec = tryspec; *spec != NULL; spec++) {
FILE *fp;
@@ -383,12 +385,22 @@ static char * getTarSpec(const char *arg)
if (!gotspec) {
rpmlog(RPMLOG_ERR, _("Failed to read spec file from %s\n"), arg);
- specFile = NULL;
+ } else {
+ /* remove trailing \n */
+ tarbuf[strlen(tarbuf)-1] = '\0';
+ specFinal = rpmExpand("%{_specdir}/%{basename:", tarbuf, "}", NULL);
+ if (rename(specFile, specFinal)) {
+ rpmlog(RPMLOG_ERR, _("Failed to rename %s to %s: %m\n"),
+ specFile, specFinal);
+ unlink(specFile);
+ specFinal = _free(specFinal);
+ }
}
exit:
+ free(specFile);
Fclose(fd);
- return specFile;
+ return specFinal;
}
static int buildForTarget(rpmts ts, const char * arg, BTA_t ba)
@@ -415,6 +427,8 @@ static int buildForTarget(rpmts ts, const char * arg, BTA_t ba)
if (buildMode == 't') {
char *srcdir = NULL, *dir;
+ if (rpmMkdirs(root, "%{_specdir}"))
+ goto exit;
specFile = getTarSpec(arg);
if (!specFile)
diff --git a/tests/rpmbuild.at b/tests/rpmbuild.at
index faca79da2..bff65303b 100644
--- a/tests/rpmbuild.at
+++ b/tests/rpmbuild.at
@@ -91,6 +91,21 @@ runroot rpmbuild \
])
AT_CLEANUP
+AT_SETUP([rpmbuild -ts <spec>])
+AT_KEYWORDS([build])
+RPMDB_INIT
+AT_CHECK([
+
+runroot rpmbuild --quiet -ts /data/SOURCES/hello-2.0.tar.gz
+runroot rpm -qpl /build/SRPMS/hello-2.0-1.src.rpm
+],
+[0],
+[hello-2.0.tar.gz
+hello.spec
+],
+[])
+AT_CLEANUP
+
# weird filename survival test
AT_SETUP([rpmbuild package with weird filenames])
AT_KEYWORDS([build])