const char* pakfire_repo_get_mirrorlist(PakfireRepo repo);
int pakfire_repo_set_mirrorlist(PakfireRepo repo, const char* mirrorlist);
+struct pakfire_mirrorlist* pakfire_repo_get_mirrors(PakfireRepo repo);
+
char* pakfire_repo_get_config(PakfireRepo repo);
int pakfire_repo_is_installed_repo(PakfireRepo repo);
#include <solv/repo.h>
+#include <pakfire/downloader.h>
+
Id pakfire_repo_add_solvable(PakfireRepo repo);
PakfireRepo pakfire_repo_create_from_repo(Pakfire pakfire, Repo* r);
Repo* pakfire_repo_get_repo(PakfireRepo repo);
Repodata* pakfire_repo_get_repodata(PakfireRepo repo);
-int pakfire_repo_download_packages(PakfireRepo repo, PakfirePackageList packages);
+struct pakfire_mirrorlist* pakfire_repo_get_mirrors(PakfireRepo repo);
#endif
#include <pakfire/errno.h>
#include <pakfire/logging.h>
#include <pakfire/package.h>
-#include <pakfire/packagelist.h>
#include <pakfire/pakfire.h>
#include <pakfire/private.h>
#include <pakfire/repo.h>
return 0;
}
+struct pakfire_mirrorlist* pakfire_repo_get_mirrors(PakfireRepo repo) {
+ return pakfire_mirrorlist_ref(repo->appdata->mirrors);
+}
+
PAKFIRE_EXPORT char* pakfire_repo_get_config(PakfireRepo repo) {
if (pakfire_repo_is_installed_repo(repo) == 0)
return NULL;
// Refresh metadata
return pakfire_repo_refresh_metadata(repo, force);
}
-
-int pakfire_repo_download_packages(PakfireRepo repo, PakfirePackageList packages) {
- int r;
-
- struct pakfire_downloader* downloader = pakfire_repo_downloader(repo);
- if (!downloader)
- return 1;
-
- const size_t num_packages = pakfire_packagelist_count(packages);
-
- for (unsigned int i = 0; i < num_packages; i++) {
- PakfirePackage pkg = pakfire_packagelist_get(packages, i);
-
- // Skip packages that are not in this repository
- if (!pakfire_package_is_in_repo(pkg, repo->repo)) {
- pakfire_package_unref(pkg);
- continue;
- }
-
- char* cache_path = pakfire_package_get_cache_path(pkg);
-
- // Add transfer to downloader
- r = pakfire_downloader_add_transfer(downloader,
- repo->appdata->mirrors, pakfire_package_get_filename(pkg), cache_path);
- if (r) {
- pakfire_package_unref(pkg);
- free(cache_path);
- goto ERROR;
- }
- }
-
- // Run the download
- r = pakfire_downloader_run(downloader);
-
-ERROR:
- pakfire_downloader_unref(downloader);
-
- return r;
-}
#############################################################################*/
#include <assert.h>
+#include <errno.h>
#include <stdlib.h>
#include <solv/transaction.h>
#include <pakfire/db.h>
+#include <pakfire/downloader.h>
#include <pakfire/i18n.h>
#include <pakfire/logging.h>
#include <pakfire/package.h>
return r;
}
+static int pakfire_transaction_download_package(PakfireTransaction transaction,
+ struct pakfire_downloader* downloader, PakfirePackage pkg) {
+ int r = 1;
+ PakfireRepo repo = NULL;
+ struct pakfire_mirrorlist* mirrors = NULL;
+ char* cache_path = NULL;
+
+ // Fetch the repository to download from
+ repo = pakfire_package_get_repo(pkg);
+ if (!repo)
+ goto ERROR;
+
+ // Fetch mirrorlist
+ mirrors = pakfire_repo_get_mirrors(repo);
+ if (!mirrors)
+ goto ERROR;
+
+ // Where to store the package?
+ cache_path = pakfire_package_get_cache_path(pkg);
+ if (!cache_path)
+ goto ERROR;
+
+ // What file to download?
+ const char* filename = pakfire_package_get_filename(pkg);
+ if (!filename)
+ goto ERROR;
+
+ // Add transfer to downloader
+ r = pakfire_downloader_add_transfer(downloader, mirrors, filename, cache_path);
+
+ERROR:
+ if (cache_path)
+ free(cache_path);
+ if (mirrors)
+ pakfire_mirrorlist_unref(mirrors);
+ if (repo)
+ pakfire_repo_unref(repo);
+
+ return r;
+}
+
PAKFIRE_EXPORT int pakfire_transaction_download(PakfireTransaction transaction) {
- /*
- XXX TODO
- This is not a very pretty solution, because we have to run a downloader
- for each repository. It would be better to add all downloads to one downloader.
- */
+ struct pakfire_downloader* downloader;
int r;
- PakfirePackageList packages = pakfire_packagelist_create(transaction->pakfire);
- if (!packages)
+ // Initialize the downloader
+ r = pakfire_downloader_create(&downloader, transaction->pakfire);
+ if (r) {
+ ERROR(transaction->pakfire, "Could not initialize downloader: %s\n",
+ strerror(errno));
return 1;
+ }
// Add all packages that need to be downloaded
for (unsigned int i = 0; i < transaction->num_steps; i++) {
// Fetch the package
PakfirePackage pkg = pakfire_step_get_package(step);
- // Add it to the list
- pakfire_packagelist_push(packages, pkg);
-
+ // Enqueue download
+ r = pakfire_transaction_download_package(transaction, downloader, pkg);
pakfire_package_unref(pkg);
- }
-
- // If the list is empty, we do not need to continue
- if (pakfire_packagelist_count(packages) == 0) {
- r = 0;
- goto ERROR;
- }
-
- Pool* pool = pakfire_get_solv_pool(transaction->pakfire);
- Repo* repo;
- int i;
-
- FOR_REPOS(i, repo) {
- PakfireRepo _repo = pakfire_repo_create_from_repo(transaction->pakfire, repo);
-
- r = pakfire_repo_download_packages(_repo, packages);
- pakfire_repo_unref(_repo);
if (r)
goto ERROR;
}
- // Success
- r = 0;
+ // Run the downloader
+ r = pakfire_downloader_run(downloader);
ERROR:
- if (packages)
- pakfire_packagelist_unref(packages);
+ pakfire_downloader_unref(downloader);
return r;
}