]> git.ipfire.org Git - pakfire.git/commitdiff
repos: Revert changing pakfire_path_relpath
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Jan 2025 10:39:16 +0000 (10:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Jan 2025 10:39:16 +0000 (10:39 +0000)
Use pakfire_path_relative instead which writes the path to the stack.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/repo.c
src/pakfire/util.c

index 51c6be0ff0ec72cded4b7cd58096adeecb4822dd..ce348e17a8b157319148692d0391fcde78abfada 100644 (file)
@@ -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;
 
index 6e53c62629fe71c3881260bacaab81eba13a834d..931a8974db14350977a1798243d3a370fd48e296 100644 (file)
@@ -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,