]> git.ipfire.org Git - pakfire.git/commitdiff
transaction: Fix download check
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 29 Apr 2021 10:46:36 +0000 (10:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 29 Apr 2021 10:46:36 +0000 (10:46 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/transaction.c

index 47ae06a088f9e8dc88f81b19f115046e0c8a3d22..fe143d5c44c42871f386b367e9076de89846b474 100644 (file)
@@ -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);