From: Michael Tremer Date: Thu, 30 Jan 2025 11:17:22 +0000 (+0000) Subject: package: Add function to destroy a package X-Git-Tag: 0.9.30~265 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b22d6414c06cecc5ff4b3942607122929afdc041;p=pakfire.git package: Add function to destroy a package Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/package.c b/src/pakfire/package.c index 8b102421..04f771db 100644 --- a/src/pakfire/package.c +++ b/src/pakfire/package.c @@ -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); } diff --git a/src/pakfire/package.h b/src/pakfire/package.h index c796b7e4..d13b0979 100644 --- a/src/pakfire/package.h +++ b/src/pakfire/package.h @@ -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); diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index ec198ef3..63575cda 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -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);