alexk / rpms / rpm

Forked from rpms/rpm 2 years ago
Clone
648606
diff -up rpm-4.10.90.git11978/lib/depends.c.rpmlib-filesystem-check rpm-4.10.90.git11978/lib/depends.c
648606
--- rpm-4.10.90.git11978/lib/depends.c.rpmlib-filesystem-check	2012-11-01 09:40:26.000000000 +0200
648606
+++ rpm-4.10.90.git11978/lib/depends.c	2012-11-05 10:53:42.294733695 +0200
648606
@@ -537,6 +537,109 @@ static int rpmdbProvides(rpmts ts, depCa
648606
     return rc;
648606
 }
648606
 
648606
+/*
648606
+ * Temporary support for live-conversion of the filesystem hierarchy
648606
+ *   mailto: kay@redhat.com, harald@redhat.com
648606
+ *   https://fedoraproject.org/wiki/Features/UsrMove
648606
+ *
648606
+ *   X-CheckUnifiedSystemdir:
648606
+ *     /bin, /sbin, /lib, /lib64 --> /usr
648606
+ *
648606
+ *   X-CheckUnifiedBindir:
648606
+ *     /usr/sbin -> /usr/bin
648606
+ *
648606
+ *   X-CheckMultiArchLibdir:
648606
+ *     /usr/lib64 /usr/lib/<platform tuple> (e.g. x86_64-linux-gnu)
648606
+ *
648606
+ * This code is not needed for new installations, it can be removed after
648606
+ * updates from older systems are no longer supported: Fedora 19 / RHEL 8.
648606
+ */
648606
+
648606
+static int CheckLink(const char *dir, const char *root)
648606
+{
648606
+    char *d = NULL;
648606
+    struct stat sbuf;
648606
+    int rc = 0;
648606
+
648606
+    if (!root)
648606
+	root = "/";
648606
+
648606
+    rasprintf(&d, "%s%s", root, dir);
648606
+    if (!d) {
648606
+	rc = -1;
648606
+	goto exit;
648606
+    }
648606
+
648606
+    /* directory or symlink does not exist, all is fine */
648606
+    if (lstat(d, &sbuf) < 0) {
648606
+	rc = 1;
648606
+	goto exit;
648606
+    }
648606
+
648606
+    /* if it is a symlink, all is fine */
648606
+    if (S_ISLNK(sbuf.st_mode))
648606
+	rc = 1;
648606
+
648606
+exit:
648606
+    free(d);
648606
+    return rc;
648606
+}
648606
+
648606
+static int CheckFilesystemHierarchy(rpmds * dsp, const char *root)
648606
+{
648606
+    static const char *dirs[] = { "bin", "sbin", "lib", "lib64" };
648606
+    int check;
648606
+    int i;
648606
+    rpmds ds;
648606
+    rpmstrPool pool = rpmdsPool(*dsp);
648606
+    int rc = 0;
648606
+
648606
+    for (i = 0; i < sizeof(dirs) / sizeof(dirs[0]); i++) {
648606
+	check = CheckLink(dirs[i], root);
648606
+	if (check < 0) {
648606
+	    rc = -1;
648606
+	    goto exit;
648606
+	}
648606
+
648606
+	if (check == 0)
648606
+	    goto exit;
648606
+    }
648606
+    ds = rpmdsSinglePool(pool, RPMTAG_PROVIDENAME,
648606
+			 "rpmlib(X-CheckUnifiedSystemdir)", "1",
648606
+			 RPMSENSE_EQUAL);
648606
+    rpmdsMerge(dsp, ds);
648606
+    rpmdsFree(ds);
648606
+
648606
+    check = CheckLink("usr/lib64", root);
648606
+    if (check < 0) {
648606
+        rc = -1;
648606
+        goto exit;
648606
+    }
648606
+    if (check > 0) {
648606
+	ds = rpmdsSinglePool(pool, RPMTAG_PROVIDENAME,
648606
+			     "rpmlib(X-CheckMultiArchLibdir)", "1",
648606
+			     RPMSENSE_EQUAL);
648606
+	rpmdsMerge(dsp, ds);
648606
+	rpmdsFree(ds);
648606
+    }
648606
+
648606
+    check = CheckLink("usr/sbin", root);
648606
+    if (check < 0) {
648606
+	rc = -1;
648606
+	goto exit;
648606
+    }
648606
+    if (check > 0) {
648606
+	ds = rpmdsSinglePool(pool, RPMTAG_PROVIDENAME,
648606
+			     "rpmlib(X-CheckUnifiedBindir)", "1",
648606
+			     RPMSENSE_EQUAL);
648606
+	rpmdsMerge(dsp, ds);
648606
+	rpmdsFree(ds);
648606
+    }
648606
+
648606
+exit:
648606
+    return rc;
648606
+}
648606
+
648606
 /**
648606
  * Check dep for an unsatisfied dependency.
648606
  * @param ts		transaction set
648606
@@ -560,8 +663,10 @@ retry:
648606
      * Check those dependencies now.
648606
      */
648606
     if (dsflags & RPMSENSE_RPMLIB) {
648606
-	if (tsmem->rpmlib == NULL)
648606
+	if (tsmem->rpmlib == NULL) {
648606
 	    rpmdsRpmlibPool(rpmtsPool(ts), &(tsmem->rpmlib), NULL);
648606
+	    CheckFilesystemHierarchy(&(tsmem->rpmlib), rpmtsRootDir(ts));
648606
+	}
648606
 	
648606
 	if (tsmem->rpmlib != NULL && rpmdsSearch(tsmem->rpmlib, dep) >= 0) {
648606
 	    rpmdsNotify(dep, "(rpmlib provides)", rc);