From: Michael Tremer Date: Tue, 28 Jan 2025 15:05:08 +0000 (+0000) Subject: repo: Add a function that imports an archive X-Git-Tag: 0.9.30~319 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9292bd04c5fdd37156b5a28ee4a498783c817508;p=pakfire.git repo: Add a function that imports an archive I know that we have been doing this in so many places, but hopefully this is now the new (soon to be unified) way to do this. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index 068e02d3..185bc70e 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -409,6 +409,38 @@ int pakfire_repo_add_archive(struct pakfire_repo* repo, return pakfire_archive_make_package(archive, repo, package); } +int pakfire_repo_import_archive(struct pakfire_repo* self, struct pakfire_archive* archive) { + struct pakfire_package* pkg = NULL; + char path[PATH_MAX]; + int r; + + // Fetch the package + r = pakfire_archive_make_package(archive, NULL, &pkg); + if (r < 0) + goto ERROR; + + // Fetch the filename this package should have + const char* filename = pakfire_package_get_filename(pkg); + if (!filename) + return -EINVAL; + + // Compose the destination path + r = pakfire_repo_path(self, path, "%s", filename); + if (r < 0) + goto ERROR; + + // Copy (or link) the archive + r = pakfire_archive_link_or_copy(archive, path); + if (r < 0) + goto ERROR; + +ERROR: + if (pkg) + pakfire_package_unref(pkg); + + return r; +} + struct pakfire_mirrorlist* pakfire_repo_get_mirrorlist(struct pakfire_repo* repo) { if (!repo->mirrorlist) { // No cache path set diff --git a/src/pakfire/repo.h b/src/pakfire/repo.h index 18aef93c..cc8d8c32 100644 --- a/src/pakfire/repo.h +++ b/src/pakfire/repo.h @@ -121,6 +121,8 @@ Id pakfire_repo_add_solvable(struct pakfire_repo* repo); int pakfire_repo_add_archive(struct pakfire_repo* repo, struct pakfire_archive* archive, struct pakfire_package** package); +int pakfire_repo_import_archive(struct pakfire_repo* self, struct pakfire_archive* archive); + int pakfire_repo_download_package(struct pakfire_xfer** xfer, struct pakfire_repo* repo, struct pakfire_package* pkg);