From: Michael Tremer Date: Fri, 12 Feb 2021 19:30:22 +0000 (+0000) Subject: libpakfire: Implement nested activation X-Git-Tag: 0.9.28~1285^2~742 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c068cdd05c60622284deefa19f29c0b0337373cb;p=pakfire.git libpakfire: Implement nested activation To avoid that we mount and umount the entire environment over and over again we mount it once for the transaction and keep a reference counter to remember when to umount again. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index e85cc2c35..71466a5e1 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -61,6 +61,7 @@ struct _Pakfire { pakfire_log_function_t log_function; int log_priority; + int activated; int nrefs; }; @@ -365,6 +366,10 @@ PAKFIRE_EXPORT int pakfire_activate(Pakfire pakfire) { if (strcmp(pakfire->path, "/") == 0) return 0; + // Do nothing if this already activated + if (pakfire->activated++) + return 0; + // Mount filesystems int r = pakfire_mount(pakfire); if (r) { @@ -377,6 +382,10 @@ PAKFIRE_EXPORT int pakfire_activate(Pakfire pakfire) { } PAKFIRE_EXPORT int pakfire_deactivate(Pakfire pakfire) { + // Do nothing if there are some activations left + if (--pakfire->activated > 0) + return 0; + return pakfire_umount(pakfire); } diff --git a/src/libpakfire/transaction.c b/src/libpakfire/transaction.c index 9e379dca3..7b37d4d02 100644 --- a/src/libpakfire/transaction.c +++ b/src/libpakfire/transaction.c @@ -388,6 +388,11 @@ PAKFIRE_EXPORT int pakfire_transaction_run(PakfireTransaction transaction) { DEBUG(transaction->pakfire, "Running Transaction %p\n", transaction); + // Activate Pakfire + r = pakfire_activate(transaction->pakfire); + if (r) + return r; + // Open the database r = pakfire_db_open(&db, transaction->pakfire, PAKFIRE_DB_READWRITE); if (r) { @@ -420,5 +425,8 @@ ERROR: // Free the database pakfire_db_unref(db); + // Deactivate Pakfire + pakfire_deactivate(transaction->pakfire); + return r; }