From: Michael Tremer Date: Thu, 29 Apr 2021 10:46:36 +0000 (+0000) Subject: transaction: Fix download check X-Git-Tag: 0.9.28~1285^2~197 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cde9923f7e1ceee73922e339a38329dce01eaaf2;p=pakfire.git transaction: Fix download check Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/transaction.c b/src/libpakfire/transaction.c index 47ae06a08..fe143d5c4 100644 --- a/src/libpakfire/transaction.c +++ b/src/libpakfire/transaction.c @@ -834,6 +834,36 @@ ERROR: return r; } +static int pakfire_transaction_package_needs_download( + struct pakfire_transaction* transaction, PakfirePackage pkg) { + pakfire_step_type_t type = pakfire_transaction_get_step_type(transaction, pkg); + switch (type) { + case PAKFIRE_STEP_INSTALL: + case PAKFIRE_STEP_REINSTALL: + case PAKFIRE_STEP_DOWNGRADE: + case PAKFIRE_STEP_UPGRADE: + break; + + // No need to download for these steps + default: + return 0; + } + + // No download required if this package is already installed + if (pakfire_package_is_installed(pkg)) + return 0; + + const char* path = pakfire_package_get_path(pkg); + + // Does the file exist? + int r = access(path, R_OK); + if (r == 0) + return 0; + + // This package needs to be downloaded + return 1; +} + PAKFIRE_EXPORT int pakfire_transaction_download(struct pakfire_transaction* transaction) { struct pakfire_downloader* downloader; int r; @@ -850,17 +880,8 @@ PAKFIRE_EXPORT int pakfire_transaction_download(struct pakfire_transaction* tran for (unsigned int i = 0; i < transaction->num; i++) { PakfirePackage pkg = transaction->packages[i]; - pakfire_step_type_t type = pakfire_transaction_get_step_type(transaction, pkg); - switch (type) { - case PAKFIRE_STEP_INSTALL: - case PAKFIRE_STEP_REINSTALL: - case PAKFIRE_STEP_DOWNGRADE: - case PAKFIRE_STEP_UPGRADE: - break; - - default: - continue; - } + if (!pakfire_transaction_package_needs_download(transaction, pkg)) + continue; // Enqueue download r = pakfire_transaction_download_package(transaction, downloader, pkg);