Kay Sievers 1439f0
diff --git a/lib/depends.c b/lib/depends.c
Kay Sievers 1439f0
index 69aecbb..5101d32 100644
Kay Sievers 1439f0
--- a/lib/depends.c
Kay Sievers 1439f0
+++ b/lib/depends.c
Kay Sievers 1439f0
@@ -386,6 +386,108 @@ static int rpmdbProvides(rpmts ts, depCache dcache, rpmds dep)
Kay Sievers 1439f0
     return rc;
Kay Sievers 1439f0
 }
Kay Sievers 1439f0
 
Kay Sievers 1439f0
+/*
Kay Sievers 1439f0
+ * Temporary support for live-conversion of the filesystem hierarchy
Kay Sievers 1439f0
+ *   mailto: kay@redhat.com, harald@redhat.com
Kay Sievers 1439f0
+ *   https://fedoraproject.org/wiki/Features/UsrMove
Kay Sievers 1439f0
+ *
Kay Sievers 1439f0
+ *   X-CheckUnifiedSystemdir:
Kay Sievers 1439f0
+ *     /bin, /sbin, /lib, /lib64 --> /usr
Kay Sievers 1439f0
+ *
Kay Sievers 1439f0
+ *   X-CheckUnifiedBindir:
Kay Sievers 1439f0
+ *     /usr/sbin -> /usr/bin
Kay Sievers 1439f0
+ *
Kay Sievers 1439f0
+ *   X-CheckMultiArchLibdir:
Kay Sievers 1439f0
+ *     /usr/lib64 /usr/lib/<platform tuple> (e.g. x86_64-linux-gnu)
Kay Sievers 1439f0
+ *
Kay Sievers 1439f0
+ * This code is not needed for new installations, it can be removed after
Kay Sievers 1439f0
+ * updates from older systems are no longer supported: Fedora 19 / RHEL 8.
Kay Sievers 1439f0
+ */
Kay Sievers 1439f0
+
Kay Sievers 1439f0
+static int CheckLink(const char *dir, const char *root)
Kay Sievers 1439f0
+{
Kay Sievers 1439f0
+    char *d = NULL;
Kay Sievers 1439f0
+    struct stat sbuf;
Kay Sievers 1439f0
+    int rc = 0;
Kay Sievers 1439f0
+
Kay Sievers 1439f0
+    if (!root)
Kay Sievers 1439f0
+	root = "/";
Kay Sievers 1439f0
+
Kay Sievers 1439f0
+    rasprintf(&d, "%s%s", root, dir);
Kay Sievers 1439f0
+    if (!d) {
Kay Sievers 1439f0
+	rc = -1;
Kay Sievers 1439f0
+	goto exit;
Kay Sievers 1439f0
+    }
Kay Sievers 1439f0
+
Kay Sievers 1439f0
+    /* directory or symlink does not exist, all is fine */
Kay Sievers 1439f0
+    if (lstat(d, &sbuf) < 0) {
Kay Sievers 1439f0
+	rc = 1;
Kay Sievers 1439f0
+	goto exit;
Kay Sievers 1439f0
+    }
Kay Sievers 1439f0
+
Kay Sievers 1439f0
+    /* if it is a symlink, all is fine */
Kay Sievers 1439f0
+    if (S_ISLNK(sbuf.st_mode))
Kay Sievers 1439f0
+	rc = 1;
Kay Sievers 1439f0
+
Kay Sievers 1439f0
+exit:
Kay Sievers 1439f0
+    free(d);
Kay Sievers 1439f0
+    return rc;
Kay Sievers 1439f0
+}
Kay Sievers 1439f0
+
Kay Sievers 1439f0
+static int CheckFilesystemHierarchy(rpmds * dsp, const char *root)
Kay Sievers 1439f0
+{
Kay Sievers 1439f0
+    static const char *dirs[] = { "bin", "sbin", "lib", "lib64" };
Kay Sievers 1439f0
+    int check;
Kay Sievers 1439f0
+    int i;
Kay Sievers 1439f0
+    rpmds ds;
Kay Sievers 1439f0
+    int rc = 0;
Kay Sievers 1439f0
+
Kay Sievers 1439f0
+    for (i = 0; i < sizeof(dirs) / sizeof(dirs[0]); i++) {
Kay Sievers 1439f0
+	check = CheckLink(dirs[i], root);
Kay Sievers 1439f0
+	if (check < 0) {
Kay Sievers 1439f0
+	    rc = -1;
Kay Sievers 1439f0
+	    goto exit;
Kay Sievers 1439f0
+	}
Kay Sievers 1439f0
+
Kay Sievers 1439f0
+	if (check == 0)
Kay Sievers 1439f0
+	    goto exit;
Kay Sievers 1439f0
+    }
Kay Sievers 1439f0
+    ds = rpmdsSingle(RPMTAG_PROVIDENAME,
Kay Sievers 1439f0
+		     "rpmlib(X-CheckUnifiedSystemdir)", "1",
Kay Sievers 1439f0
+		     RPMSENSE_EQUAL);
Kay Sievers 1439f0
+    rpmdsMerge(dsp, ds);
Kay Sievers 1439f0
+    rpmdsFree(ds);
Kay Sievers 1439f0
+
Kay Sievers 1439f0
+    check = CheckLink("usr/lib64", root);
Kay Sievers 1439f0
+    if (check < 0) {
Kay Sievers 1439f0
+        rc = -1;
Kay Sievers 1439f0
+        goto exit;
Kay Sievers 1439f0
+    }
Kay Sievers 1439f0
+    if (check > 0) {
Kay Sievers 1439f0
+	ds = rpmdsSingle(RPMTAG_PROVIDENAME,
Kay Sievers 1439f0
+			 "rpmlib(X-CheckMultiArchLibdir)", "1",
Kay Sievers 1439f0
+			 RPMSENSE_EQUAL);
Kay Sievers 1439f0
+	rpmdsMerge(dsp, ds);
Kay Sievers 1439f0
+	rpmdsFree(ds);
Kay Sievers 1439f0
+    }
Kay Sievers 1439f0
+
Kay Sievers 1439f0
+    check = CheckLink("usr/sbin", root);
Kay Sievers 1439f0
+    if (check < 0) {
Kay Sievers 1439f0
+	rc = -1;
Kay Sievers 1439f0
+	goto exit;
Kay Sievers 1439f0
+    }
Kay Sievers 1439f0
+    if (check > 0) {
Kay Sievers 1439f0
+	ds = rpmdsSingle(RPMTAG_PROVIDENAME,
Kay Sievers 1439f0
+			 "rpmlib(X-CheckUnifiedBindir)", "1",
Kay Sievers 1439f0
+			 RPMSENSE_EQUAL);
Kay Sievers 1439f0
+	rpmdsMerge(dsp, ds);
Kay Sievers 1439f0
+	rpmdsFree(ds);
Kay Sievers 1439f0
+    }
Kay Sievers 1439f0
+
Kay Sievers 1439f0
+exit:
Kay Sievers 1439f0
+    return rc;
Kay Sievers 1439f0
+}
Kay Sievers 1439f0
+
Kay Sievers 1439f0
 /**
Kay Sievers 1439f0
  * Check dep for an unsatisfied dependency.
Kay Sievers 1439f0
  * @param ts		transaction set
Kay Sievers 1439f0
@@ -410,9 +512,11 @@ retry:
Kay Sievers 1439f0
      */
Kay Sievers 1439f0
     if (dsflags & RPMSENSE_RPMLIB) {
Kay Sievers 1439f0
 	static int oneshot = -1;
Kay Sievers 1439f0
-	if (oneshot) 
Kay Sievers 1439f0
+	if (oneshot) {
Kay Sievers 1439f0
 	    oneshot = rpmdsRpmlib(&rpmlibP, NULL);
Kay Sievers 1439f0
-	
Kay Sievers 1439f0
+	    CheckFilesystemHierarchy(&rpmlibP, rpmtsRootDir(ts));
Kay Sievers 1439f0
+	}
Kay Sievers 1439f0
+
Kay Sievers 1439f0
 	if (rpmlibP != NULL && rpmdsSearch(rpmlibP, dep) >= 0) {
Kay Sievers 1439f0
 	    rpmdsNotify(dep, "(rpmlib provides)", rc);
Kay Sievers 1439f0
 	    goto exit;