]> git.ipfire.org Git - pakfire.git/commitdiff
packages: Return the actual error when we fail to open an archive
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 15 Feb 2025 13:11:28 +0000 (13:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 15 Feb 2025 13:11:28 +0000 (13:11 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/package.c
src/pakfire/package.h
src/pakfire/repo.c
src/pakfire/transaction.c

index 388a00f109f2babc988417f69529465cb668c443..6c32be38baa9a772eb3e0fade66c8897ef145f01 100644 (file)
@@ -2143,25 +2143,24 @@ ERROR:
        return NULL;
 }
 
-struct pakfire_archive* pakfire_package_get_archive(struct pakfire_package* pkg) {
-       struct pakfire_archive* archive = NULL;
+int pakfire_package_get_archive(struct pakfire_package* pkg, struct pakfire_archive** archive) {
        const char* path = NULL;
        int r;
 
        // Fetch the path
        path = pakfire_package_get_path(pkg);
        if (!path)
-               return NULL;
+               return -errno;
 
        // Open archive
-       r = pakfire_archive_open(&archive, pkg->pakfire, path);
-       if (r) {
-               ERROR(pkg->ctx, "Could not open archive for %s (at %s): %m\n",
-                       pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA), path);
-               return NULL;
+       r = pakfire_archive_open(archive, pkg->pakfire, path);
+       if (r < 0) {
+               ERROR(pkg->ctx, "Could not open archive for %s (at %s): %s\n",
+                       pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA), path, strerror(-r));
+               return r;
        }
 
-       return archive;
+       return 0;
 }
 
 struct pakfire_package_filelist_search {
index 1bff6e399c9a35a96640bb12bf80554adde40bcc..935e95cb465d36fd5f1ad80a707fe0112f04f5e7 100644 (file)
@@ -145,7 +145,7 @@ struct pakfire_repo* pakfire_package_get_repo(struct pakfire_package* pkg);
 
 char* pakfire_package_dump(struct pakfire_package* pkg, int flags);
 
-struct pakfire_archive* pakfire_package_get_archive(struct pakfire_package* pkg);
+int pakfire_package_get_archive(struct pakfire_package* pkg, struct pakfire_archive** archive);
 
 struct pakfire_filelist* pakfire_package_get_filelist(struct pakfire_package* pkg);
 int pakfire_package_set_filelist(struct pakfire_package* pkg, struct pakfire_filelist* filelist);
index 27eed4e7b04052f175d632a44371692595366ff1..b8ff0fdad4a62b236e30fdb6facc0115be7ebc3e 100644 (file)
@@ -2697,9 +2697,9 @@ static int __pakfire_repo_walk_archives(
                return -EINVAL;
 
        // Fetch the archive
-       archive = pakfire_package_get_archive(pkg);
-       if (!archive)
-               return -errno;
+       r = pakfire_package_get_archive(pkg, &archive);
+       if (r < 0)
+               return r;
 
        // Call the callback
        r = state->callback(ctx, pkg, archive, state->data);
index 5bf5c1aab0e97d5d86c59f1e7a74b53a75cfb854..177b2acaca9db8807b86ed798b9a05dc92486056 100644 (file)
@@ -1750,6 +1750,8 @@ static int pakfire_transaction_run_steps(struct pakfire_transaction* transaction
 }
 
 static int pakfire_transaction_open_archives(struct pakfire_transaction* transaction) {
+       int r;
+
        for (unsigned int i = 0; i < transaction->num; i++) {
                struct pakfire_package* pkg = transaction->packages[i];
 
@@ -1772,9 +1774,10 @@ static int pakfire_transaction_open_archives(struct pakfire_transaction* transac
                                continue;
                }
 
-               transaction->archives[i] = pakfire_package_get_archive(pkg);
-               if (!transaction->archives[i])
-                       return 1;
+               // Open the archive
+               r = pakfire_package_get_archive(pkg, &transaction->archives[i]);
+               if (r < 0)
+                       return r;
        }
 
        return 0;