[Rpm-maint] [PATCH] Unbreak short-circuited binary builds

Panu Matilainen pmatilai at redhat.com
Thu Jan 5 11:47:28 UTC 2017


Commit bbfe1f86b2e4b5c0bd499d9f3dd9de9c9c20fff2 broke short-circuited
binary builds (which can be handy for testing when working on large
packages), eg:
     rpmbuild -bi foo.spec; rpmbuild -bb --short-circuit foo.spec

The problem is that in a short-circuited build all the links already
exist and point to the right place, but the code doesn't realize this
and creates new links instead, which leaves the old links unowned
in the buildroot which ultimately causes the build to fail with
"Installed (but unpackaged) file(s) found" for the previously created
build-id links.

When checking for pre-existing links see if they already point to
the right file and in that case just reuse it instead of creating new ones.
---
 build/files.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/build/files.c b/build/files.c
index 0504f47..3cf0575 100644
--- a/build/files.c
+++ b/build/files.c
@@ -1563,6 +1563,7 @@ static int addNewIDSymlink(FileList fl,
     const char *linkerr = _("failed symlink");
     int rc = 0;
     int nr = 0;
+    int exists = 0;
     char *origpath, *linkpath;
 
     if (isDbg)
@@ -1572,6 +1573,16 @@ static int addNewIDSymlink(FileList fl,
     origpath = linkpath;
 
     while (faccessat(AT_FDCWD, linkpath, F_OK, AT_SYMLINK_NOFOLLOW) == 0) {
+	char ltarget[PATH_MAX];
+	ssize_t llen;
+	/* In short-circuited builds the link might already exist  */
+	if ((llen = readlink(linkpath, ltarget, sizeof(ltarget)-1)) != -1) {
+	    ltarget[llen] = '\0';
+	    if (rstreq(ltarget, targetpath)) {
+		exists = 1;
+		break;
+	    }
+	}
 	if (nr > 0)
 	    free(linkpath);
 	nr++;
@@ -1583,7 +1594,7 @@ static int addNewIDSymlink(FileList fl,
     if (nr > 0 && isCompat)
 	rasprintf (&symtarget, "%s.%d", targetpath, nr);
 
-    if (symlink(symtarget, linkpath) < 0) {
+    if (!exists && symlink(symtarget, linkpath) < 0) {
 	rc = 1;
 	rpmlog(RPMLOG_ERR, "%s: %s -> %s: %m\n",
 	       linkerr, linkpath, symtarget);
-- 
2.9.3



More information about the Rpm-maint mailing list