]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
transactions: Add hack to ensure UsrMove works
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 28 Nov 2022 16:21:34 +0000 (16:21 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 28 Nov 2022 16:21:34 +0000 (16:21 +0000)
This is the only way to avoid chaos, but it is ugly.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/transaction.c

index 512fbab42ee1f5ead1ccfc905fd5c1df14ab9641..a7a163dcd11fd6cdb0843043d1f7e0a581701fba 100644 (file)
@@ -1070,6 +1070,70 @@ static int pakfire_transaction_open_archives(struct pakfire_transaction* transac
        return 0;
 }
 
+static int pakfire_usrmove_symlink(struct pakfire* pakfire,
+               const char* src, const char* dst) {
+       char link[PATH_MAX];
+       char path[PATH_MAX];
+       int r;
+
+       // Compose the link path
+       r = pakfire_path(pakfire, link, "%s", src);
+       if (r)
+               return r;
+
+       // Exit if the link exists
+       if (pakfire_path_exists(link))
+               return 0;
+
+       // Compose the destination path
+       r = pakfire_path(pakfire, path, "%s", dst);
+       if (r)
+               return r;
+
+       // Make sure the destination exists
+       r = pakfire_mkdir(path, 755);
+       if (r)
+               return r;
+
+       // Create the symlink
+       r = symlink(dst, link);
+       if (r) {
+               DEBUG(pakfire, "Could not create symlink %s to %s: %m\n", dst, link);
+               return r;
+       }
+
+       DEBUG(pakfire, "Created symlink %s --> %s\n", link, dst);
+
+       return 0;
+}
+
+/*
+       This is an ugly helper function that helps us to make sure
+       that /bin, /sbin, /lib and /lib64 are symlinks to their
+       corresponding path in /usr.
+*/
+static int pakfire_usrmove(struct pakfire* pakfire) {
+       int r;
+
+       r = pakfire_usrmove_symlink(pakfire, "/bin", "usr/bin");
+       if (r)
+               return r;
+
+       r = pakfire_usrmove_symlink(pakfire, "/sbin", "usr/sbin");
+       if (r)
+               return r;
+
+       r = pakfire_usrmove_symlink(pakfire, "/lib", "usr/lib");
+       if (r)
+               return r;
+
+       r = pakfire_usrmove_symlink(pakfire, "/lib64", "usr/lib64");
+       if (r)
+               return r;
+
+       return r;
+}
+
 static int pakfire_transaction_perform(struct pakfire_transaction* transaction) {
        struct pakfire_repo* repo = NULL;
        struct pakfire_db* db;
@@ -1094,6 +1158,11 @@ static int pakfire_transaction_perform(struct pakfire_transaction* transaction)
        if (r)
                goto ERROR;
 
+       // Make sure /usr-move is working
+       r = pakfire_usrmove(transaction->pakfire);
+       if (r)
+               goto ERROR;
+
        // Execute all pre transaction actions
        r = pakfire_transaction_run_steps(transaction, db, PAKFIRE_ACTION_PRETRANS);
        if (r)