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, IFF %install did not execute (which means we must be in
 --short-circuited build)
---

V2: Only permit pre-existing build-id links on short-circuited builds

 build/files.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/build/files.c b/build/files.c
index 85cb984..86f1cec 100644
--- a/build/files.c
+++ b/build/files.c
@@ -1592,11 +1592,12 @@ exit:
 
 static int addNewIDSymlink(FileList fl,
                           char *targetpath, char *idlinkpath,
-                          int isDbg, int isCompat)
+                          int isDbg, int isCompat, int didInstall)
 {
     const char *linkerr = _("failed symlink");
     int rc = 0;
     int nr = 0;
+    int exists = 0;
     char *origpath, *linkpath;
 
     if (isDbg)
@@ -1606,6 +1607,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 could already exist  */
+       if (!didInstall && (llen = readlink(linkpath, ltarget, 
sizeof(ltarget)-1)) != -1) {
+           ltarget[llen] = '\0';
+           if (rstreq(ltarget, targetpath)) {
+               exists = 1;
+               break;
+           }
+       }
        if (nr > 0)
            free(linkpath);
        nr++;
@@ -1617,7 +1628,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);
@@ -1662,7 +1673,7 @@ static int addNewIDSymlink(FileList fl,
     return rc;
 }
 
-static int generateBuildIDs(FileList fl)
+static int generateBuildIDs(FileList fl, int didInstall)
 {
     int rc = 0;
     int i;
@@ -1878,7 +1889,7 @@ static int generateBuildIDs(FileList fl)
                                  buildidsubdir, &ids[i][2]);
                        rasprintf(&targetpath, targetpattern, paths[i]);
                        rc = addNewIDSymlink(fl, targetpath, linkpath,
-                                            isDbg, 0);
+                                            isDbg, 0, didInstall);
 
                        /* We might want to have a link from the debug
                           build_ids dir to the main one. We create it
@@ -1910,7 +1921,7 @@ static int generateBuildIDs(FileList fl)
                                      "../../../.build-id%s/%s",
                                      subdir, &ids[i][2]);
                            rc = addNewIDSymlink(fl, targetpath, linkpath,
-                                                0, 1);
+                                                0, 1, didInstall);
                        }
 
                        if (rc == 0 && isDbg
@@ -1948,7 +1959,7 @@ static int generateBuildIDs(FileList fl)
                                rasprintf(&targetpath, "../../../../..%s",
                                          targetstr);
                                rc = addNewIDSymlink(fl, targetpath,
-                                                    linkpath, 0, 0);
+                                                    linkpath, 0, 0, 
didInstall);
                                free(targetstr);
                            }
                        }
@@ -2384,7 +2395,7 @@ static rpmRC processPackageFiles(rpmSpec spec, 
rpmBuildPkgFlags pkgFlags,
        goto exit;
 
 #if HAVE_LIBDW
-    if (generateBuildIDs (&fl) != 0) {
+    if (generateBuildIDs (&fl, didInstall) != 0) {
        rpmlog(RPMLOG_ERR, _("Generating build-id links failed\n"));
        fl.processingFailed = 1;
        goto exit;
-- 
2.9.3

_______________________________________________
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint

Reply via email to