]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Implement nested activation
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 12 Feb 2021 19:30:22 +0000 (19:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 12 Feb 2021 19:30:22 +0000 (19:30 +0000)
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 <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c
src/libpakfire/transaction.c

index e85cc2c358cec3bfb10d5c6759edd67eb14584b4..71466a5e15a4b4612c7c129babde23a30d8dfb76 100644 (file)
@@ -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);
 }
 
index 9e379dca34205e1c013fb73b4ff9db528d9120dc..7b37d4d02b8c26b7498a9da084d26770fd9258e4 100644 (file)
@@ -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;
 }