From ff9fc57230db1caf38dd37d2e4d13977be591b65 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 28 Nov 2022 16:21:34 +0000 Subject: [PATCH] transactions: Add hack to ensure UsrMove works This is the only way to avoid chaos, but it is ugly. Signed-off-by: Michael Tremer --- src/libpakfire/transaction.c | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/libpakfire/transaction.c b/src/libpakfire/transaction.c index 512fbab42..a7a163dcd 100644 --- a/src/libpakfire/transaction.c +++ b/src/libpakfire/transaction.c @@ -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) -- 2.39.5