From: Michael Tremer Date: Thu, 30 Jan 2025 22:07:21 +0000 (+0000) Subject: repo: Implement the reverse of pakfire_package_get_path() X-Git-Tag: 0.9.30~234 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c1d9bb940a28bd492c3293f66ddc53d6f61f0502;p=pakfire.git repo: Implement the reverse of pakfire_package_get_path() This hopefully fixes that we will copy/link packages to themselves. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/archive.c b/src/pakfire/archive.c index 0915c8ac..a04aa81f 100644 --- a/src/pakfire/archive.c +++ b/src/pakfire/archive.c @@ -1545,6 +1545,7 @@ static int pakfire_archive_import_filelist_from_json( static int pakfire_archive_make_package_from_json(struct pakfire_archive* archive, struct pakfire_repo* repo, struct pakfire_package** package) { struct pakfire_package* pkg = NULL; + char path[PATH_MAX]; int r; // Calculate digest @@ -1569,8 +1570,15 @@ static int pakfire_archive_make_package_from_json(struct pakfire_archive* archiv nevra, pkg, archive); #endif + // Make the path where this archive should be stored + r = pakfire_repo_make_path(repo, path, archive, pkg); + if (r < 0) + goto ERROR; + // Set path - pakfire_package_set_string(pkg, PAKFIRE_PKG_PATH, archive->path); + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_PATH, path); + if (r < 0) + goto ERROR; // Set digest switch (PAKFIRE_ARCHIVE_CHECKSUM) { diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index f97e4825..516d905c 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -227,16 +227,6 @@ int __pakfire_repo_path(struct pakfire_repo* repo, return __pakfire_cache_path(repo->pakfire, path, length, "%s/%s", name, buffer); } -#define pakfire_repo_relpath(repo, result, path) \ - __pakfire_repo_relpath(repo, result, sizeof(result), path); - -static int __pakfire_repo_relpath(struct pakfire_repo* self, char* result, size_t length, const char* path) { - // Fetch the repo's base path - const char* basepath = pakfire_repo_get_path(self); - - return __pakfire_path_relative(result, length, basepath, path); -} - static int pakfire_repo_xfer_create(struct pakfire_xfer** xfer, struct pakfire_repo* repo, const char* url, ...) __attribute__((format(printf, 3, 4))); @@ -414,18 +404,9 @@ Id pakfire_repo_add_solvable(struct pakfire_repo* repo) { return id; } -int pakfire_repo_import_archive(struct pakfire_repo* self, - struct pakfire_archive* archive, struct pakfire_package** package) { - struct pakfire_package* pkg = NULL; +int __pakfire_repo_make_path(struct pakfire_repo* self, char* path, size_t length, + struct pakfire_archive* archive, struct pakfire_package* pkg) { const char* uuid = NULL; - char relpath[PATH_MAX]; - char path[PATH_MAX]; - int r; - - // Add the metadata - r = pakfire_archive_make_package(archive, self, &pkg); - if (r < 0) - goto ERROR; // Fetch NEVRA const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA); @@ -435,51 +416,57 @@ int pakfire_repo_import_archive(struct pakfire_repo* self, // Fetch the filename this package should have const char* filename = pakfire_package_get_filename(pkg); if (!filename) - return -EINVAL; + return -ENODATA; // Compose the destination path switch (self->appdata->fs_layout) { case PAKFIRE_REPO_FLAT: - r = pakfire_repo_path(self, path, "%s", filename); - if (r < 0) - goto ERROR; - break; + return __pakfire_repo_path(self, path, length, "%s", filename); case PAKFIRE_REPO_UUID: // Fetch the UUID uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID); if (!uuid) { ERROR(self->ctx, "%s does not have a UUID\n", nevra); - r = -EINVAL; - goto ERROR; + return -ENODATA; } - r = pakfire_repo_path(self, path, "%s/%s", uuid, filename); - if (r < 0) - goto ERROR; - break; + return __pakfire_repo_path(self, path, length, "%s/%s", uuid, filename); // In virtual mode, we don't actually import the file case PAKFIRE_REPO_VIRT: - goto END; + return __pakfire_string_set(path, length, pakfire_archive_get_path(archive)); } - // Compose the path of the archive relative to the repository path - r = pakfire_repo_relpath(self, relpath, path); - if (r < 0) - goto ERROR; + return -EINVAL; +} - // Copy (or link) the archive - r = pakfire_archive_link_or_copy(archive, path); - if (r < 0) - goto ERROR; +int pakfire_repo_import_archive(struct pakfire_repo* self, + struct pakfire_archive* archive, struct pakfire_package** package) { + struct pakfire_package* pkg = NULL; + char path[PATH_MAX]; + int r; - // Reset the path - r = pakfire_package_set_string(pkg, PAKFIRE_PKG_PATH, relpath); + // This only works on internal or local repositories + if (!pakfire_repo_is_internal(self) && !pakfire_repo_is_local(self)) + return -ENOTSUP; + + // Add the metadata + r = pakfire_archive_make_package(archive, self, &pkg); if (r < 0) goto ERROR; -END: + // Fetch package path + const char* arc_path = pakfire_archive_get_path(archive); + const char* pkg_path = pakfire_package_get_path(pkg); + + // Copy (or link) the archive + if (!pakfire_string_equals(arc_path, pkg_path)) { + r = pakfire_archive_link_or_copy(archive, path); + if (r < 0) + goto ERROR; + } + // Return the package if requested if (package) *package = pakfire_package_ref(pkg); diff --git a/src/pakfire/repo.h b/src/pakfire/repo.h index df2bcbc9..3c703f63 100644 --- a/src/pakfire/repo.h +++ b/src/pakfire/repo.h @@ -127,6 +127,11 @@ void pakfire_repo_has_changed(struct pakfire_repo* repo); int pakfire_repo_internalize(struct pakfire_repo* repo, int flags); Id pakfire_repo_add_solvable(struct pakfire_repo* repo); +#define pakfire_repo_make_path(repo, path, archive, pkg) \ + __pakfire_repo_make_path(repo, path, sizeof(path), archive, pkg) +int __pakfire_repo_make_path(struct pakfire_repo* self, + char* path, size_t length, struct pakfire_archive* archive, struct pakfire_package* pkg); + int pakfire_repo_import_archive(struct pakfire_repo* self, struct pakfire_archive* archive, struct pakfire_package** package);