michal-grzedzicki / rpms / rpm

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