]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Make the umount code clearer
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 17 Oct 2024 17:40:01 +0000 (17:40 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 17 Oct 2024 17:40:01 +0000 (17:40 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c

index 4b004bd4a676b2adf2f8f33a43c630d4c149bae9..c31fffb52268e658f76e873f0984aac0750bcf82 100644 (file)
@@ -83,6 +83,7 @@ struct pakfire {
        enum pakfire_internal_flags {
                PAKFIRE_HAS_PATH        = (1 << 0),
                PAKFIRE_DESTROY_ON_FREE = (1 << 1),
+               PAKFIRE_UMOUNT_PATH     = (1 << 2),
        } internal_flags;
 
        // Lock
@@ -394,19 +395,29 @@ static void pakfire_free(struct pakfire* pakfire) {
        }
 
        // Umount the snapshot
-       if (pakfire->snapshot)
-               pakfire_snapshot_unref(pakfire->snapshot);
+       if (pakfire->snapshot) {
+               r = pakfire_snapshot_umount(pakfire->snapshot);
+               if (r)
+                       CTX_ERROR(pakfire->ctx, "Could not umount the snapshot: %s\n", strerror(-r));
 
-       if (pakfire->internal_flags & PAKFIRE_DESTROY_ON_FREE) {
-               CTX_DEBUG(pakfire->ctx, "Destroying %s\n", pakfire->path);
+               pakfire_snapshot_unref(pakfire->snapshot);
+       }
 
-               // Umount the ramdisk
-               r = umount2(pakfire->path, MNT_DETACH);
+       // Umount path
+       if (pakfire->internal_flags & PAKFIRE_UMOUNT_PATH) {
+               r = umount2(pakfire->path, 0);
                if (r)
                        CTX_ERROR(pakfire->ctx, "Could not umount ramdisk at %s: %m\n", pakfire->path);
+       }
+
+       // Destroy path
+       if (pakfire->internal_flags & PAKFIRE_DESTROY_ON_FREE) {
+               CTX_DEBUG(pakfire->ctx, "Destroying %s\n", pakfire->path);
 
                // Destroy the temporary directory
-               pakfire_rmtree(pakfire->path, 0);
+               r = pakfire_rmtree(pakfire->path, 0);
+               if (r)
+                       CTX_ERROR(pakfire->ctx, "Could not destroy %s: %s\n", pakfire->path, strerror(-r));
        }
 
        pakfire_repo_free_all(pakfire);
@@ -887,6 +898,9 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx*
                                r = -errno;
                                goto ERROR;
                        }
+
+                       // Umount path later
+                       p->internal_flags |= PAKFIRE_UMOUNT_PATH;
                }
        }