]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Move cachiing Archive from Package to Step
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Jun 2019 23:54:28 +0000 (00:54 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Jun 2019 23:54:28 +0000 (00:54 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/package.c
src/libpakfire/step.c

index ca0c7f50bf7d23085b0fa641fb5a8052f63ef20c..c8242d9e38840be55052dedd5637c9693fc60298 100644 (file)
@@ -46,7 +46,6 @@ struct _PakfirePackage {
        Pakfire pakfire;
        Id id;
        PakfireFile filelist;
-       PakfireArchive archive;
        int nrefs;
 };
 
@@ -91,7 +90,6 @@ static void pakfire_package_free(PakfirePackage pkg) {
        DEBUG(pkg->pakfire, "Releasing Package at %p\n", pkg);
        pakfire_unref(pkg->pakfire);
 
-       pakfire_archive_unref(pkg->archive);
        pakfire_package_filelist_remove(pkg);
        pakfire_free(pkg);
 }
@@ -892,15 +890,13 @@ PAKFIRE_EXPORT char* pakfire_package_get_cache_path(PakfirePackage pkg) {
 }
 
 PAKFIRE_EXPORT PakfireArchive pakfire_package_get_archive(PakfirePackage pkg) {
-       // Return the package if it has already been opened
-       if (pkg->archive)
-               return pakfire_archive_ref(pkg->archive);
-
        // Otherwise open the archive from the cache
        char* path = pakfire_package_get_cache_path(pkg);
-       PakfireArchive archive = pakfire_archive_open(pkg->pakfire, path);
+       if (!path)
+               return NULL;
 
-       // Free resources
+       // Open archive
+       PakfireArchive archive = pakfire_archive_open(pkg->pakfire, path);
        pakfire_free(path);
 
        return archive;
index e8fc54a830eb67beb6afa647b993958377d98579..610dcf3faab791e2c7ac16140362c0a57490ae09 100644 (file)
@@ -38,6 +38,7 @@
 struct _PakfireStep {
        Pakfire pakfire;
        PakfirePackage package;
+       PakfireArchive archive;
        pakfire_step_type_t type;
        int nrefs;
 };
@@ -108,6 +109,7 @@ static void pakfire_step_free(PakfireStep step) {
        DEBUG(step->pakfire, "Releasing Step at %p\n", step);
 
        pakfire_package_unref(step->package);
+       pakfire_archive_unref(step->archive);
        pakfire_unref(step->pakfire);
        pakfire_free(step);
 }
@@ -222,8 +224,8 @@ static int pakfire_step_verify(PakfireStep step) {
                return 1;
 
        // Fetch the archive
-       PakfireArchive archive = pakfire_package_get_archive(step->package);
-       if (!archive) {
+       step->archive = pakfire_package_get_archive(step->package);
+       if (!step->archive) {
                char* nevra = pakfire_package_get_nevra(step->package);
                char* cache_path = pakfire_package_get_cache_path(step->package);
 
@@ -237,8 +239,13 @@ static int pakfire_step_verify(PakfireStep step) {
        }
 
        // Verify the archive
-       pakfire_archive_verify_status_t status = pakfire_archive_verify(archive);
-       pakfire_archive_unref(archive);
+       pakfire_archive_verify_status_t status = pakfire_archive_verify(step->archive);
+
+       // Log error
+       if (status) {
+               const char* error = pakfire_archive_verify_strerror(status);
+               ERROR(step->pakfire, "Archive verification failed: %s\n", error);
+       }
 
        return status;
 }