From: Michael Tremer Date: Thu, 17 Oct 2024 17:40:01 +0000 (+0000) Subject: pakfire: Make the umount code clearer X-Git-Tag: 0.9.30~1030 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1a4fb8683e1053978a67b9b7ecb502f8e49bfe8;p=pakfire.git pakfire: Make the umount code clearer Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 4b004bd4a..c31fffb52 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -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; } }