]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Add a function that imports an archive
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Jan 2025 15:05:08 +0000 (15:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Jan 2025 15:05:08 +0000 (15:05 +0000)
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 <michael.tremer@ipfire.org>
src/pakfire/repo.c
src/pakfire/repo.h

index 068e02d3f844380ddbcf6b14c7e29366e13a20ff..185bc70e1990dfedd3c8a17f84d16594cd1f537d 100644 (file)
@@ -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
index 18aef93c25f568816826d865fef0b5516be292e5..cc8d8c3264e6f6e2c38c495a7f54347a3ed9174a 100644 (file)
@@ -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);