From: Michael Tremer Date: Thu, 30 Jan 2025 10:39:16 +0000 (+0000) Subject: repos: Revert changing pakfire_path_relpath X-Git-Tag: 0.9.30~274 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a8a33741661eb4ec14321ffc6ac7ea9719ea306;p=pakfire.git repos: Revert changing pakfire_path_relpath Use pakfire_path_relative instead which writes the path to the stack. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index 51c6be0f..ce348e17 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -229,11 +229,14 @@ static int __pakfire_repo_path(struct pakfire_repo* repo, return __pakfire_cache_path(repo->pakfire, path, length, "%s/%s", name, buffer); } -static const char* pakfire_repo_relpath(struct pakfire_repo* self, const char* path) { +#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_relpath(basepath, path); + return __pakfire_path_relative(result, length, basepath, path); } static int pakfire_repo_xfer_create(struct pakfire_xfer** xfer, struct pakfire_repo* repo, @@ -426,6 +429,7 @@ int pakfire_repo_add_archive(struct pakfire_repo* repo, int pakfire_repo_import_archive(struct pakfire_repo* self, struct pakfire_archive* archive) { struct pakfire_package* pkg = NULL; const char* uuid = NULL; + char relpath[PATH_MAX]; char path[PATH_MAX]; int r; @@ -471,13 +475,17 @@ int pakfire_repo_import_archive(struct pakfire_repo* self, struct pakfire_archiv break; } + r = pakfire_repo_relpath(self, relpath, path); + if (r < 0) + goto ERROR; + // Copy (or link) the archive r = pakfire_archive_link_or_copy(archive, path); if (r < 0) goto ERROR; // Reset the path - r = pakfire_package_set_string(pkg, PAKFIRE_PKG_PATH, pakfire_repo_relpath(self, path)); + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_PATH, relpath); if (r < 0) goto ERROR; diff --git a/src/pakfire/util.c b/src/pakfire/util.c index 6e53c626..931a8974 100644 --- a/src/pakfire/util.c +++ b/src/pakfire/util.c @@ -46,18 +46,10 @@ const char* pakfire_path_relpath(const char* root, const char* path) { return NULL; } - // Return NULL if path does not start with root - if (!pakfire_string_startswith(path, root)) - return NULL; - - // Skip the root - path += strlen(root); - - // Skip any leading slashes - while (path && *path == '/') - path++; + if (pakfire_string_startswith(path, root)) + return path + strlen(root); - return path; + return NULL; } int pakfire_file_write(struct pakfire* pakfire, const char* path,