From 1ee4b36ff7c21e42ce6c0a320697a1fa167ab89a Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 15 Feb 2025 13:11:28 +0000 Subject: [PATCH] packages: Return the actual error when we fail to open an archive Signed-off-by: Michael Tremer --- src/pakfire/package.c | 17 ++++++++--------- src/pakfire/package.h | 2 +- src/pakfire/repo.c | 6 +++--- src/pakfire/transaction.c | 9 ++++++--- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/pakfire/package.c b/src/pakfire/package.c index 388a00f1..6c32be38 100644 --- a/src/pakfire/package.c +++ b/src/pakfire/package.c @@ -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 { diff --git a/src/pakfire/package.h b/src/pakfire/package.h index 1bff6e39..935e95cb 100644 --- a/src/pakfire/package.h +++ b/src/pakfire/package.h @@ -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); diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index 27eed4e7..b8ff0fda 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -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); diff --git a/src/pakfire/transaction.c b/src/pakfire/transaction.c index 5bf5c1aa..177b2aca 100644 --- a/src/pakfire/transaction.c +++ b/src/pakfire/transaction.c @@ -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; -- 2.39.5