]> git.ipfire.org Git - pakfire.git/commitdiff
package: Add function to destroy a package
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Jan 2025 11:17:22 +0000 (11:17 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Jan 2025 11:17:22 +0000 (11:17 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/package.c
src/pakfire/package.h
src/pakfire/repo.c

index 8b102421d93be60c154bc0d339bd4f98b65b15b5..04f771dbcb77c9a39740cbe4bd504d53f03c7bd5 100644 (file)
@@ -299,6 +299,24 @@ struct pakfire_package* pakfire_package_unref(struct pakfire_package* pkg) {
        return NULL;
 }
 
+/*
+       Destroys the package (i.e. removes its membership from any repository)
+*/
+int pakfire_package_destroy(struct pakfire_package* self) {
+       Solvable* s = get_solvable(self);
+
+       // Remove the reference to the repository
+       s->repo = NULL;
+
+       // If we have a cached repository, drop it, too
+       if (self->repo) {
+               pakfire_repo_unref(self->repo);
+               self->repo = NULL;
+       }
+
+       return 0;
+}
+
 struct pakfire* pakfire_package_get_pakfire(struct pakfire_package* pkg) {
        return pakfire_ref(pkg->pakfire);
 }
index c796b7e423871af6a13d8b2136a0b3f6a36f29d5..d13b0979492eb752ae66b06513bdfad34c0b169a 100644 (file)
@@ -85,6 +85,10 @@ int pakfire_package_create(struct pakfire_package** package, struct pakfire* pak
 
 struct pakfire_package* pakfire_package_ref(struct pakfire_package* pkg);
 struct pakfire_package* pakfire_package_unref(struct pakfire_package* pkg);
+
+// Destroy
+int pakfire_package_destroy(struct pakfire_package* self);
+
 struct pakfire* pakfire_package_get_pakfire(struct pakfire_package* pkg);
 
 int pakfire_package_eq(struct pakfire_package* pkg1, struct pakfire_package* pkg2);
index ec198ef3d3538f32434635f3a7b443e4064bb919..63575cdaffa6012eba0f21971fccdf56e1fbc11a 100644 (file)
@@ -487,15 +487,19 @@ int pakfire_repo_import_archive(struct pakfire_repo* self,
        if (r < 0)
                goto ERROR;
 
-ERROR:
-
-       // XXX REMOVE THE PACKAGE METDATA FROM THIS REPOSITORY
-
 END:
        // Return the package if requested
        if (package)
                *package = pakfire_package_ref(pkg);
 
+       goto CLEANUP;
+
+ERROR:
+       // Destroy the package if the import wasn't successful
+       if (pkg)
+               pakfire_package_destroy(pkg);
+
+CLEANUP:
        if (pkg)
                pakfire_package_unref(pkg);