dcavalca / rpms / rpm

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