]> git.ipfire.org Git - pakfire.git/commitdiff
file: Store the absolute path
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Mar 2021 22:04:45 +0000 (22:04 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Mar 2021 22:04:45 +0000 (22:04 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/file.c
src/libpakfire/include/pakfire/file.h

index 6aeb46e147fdcf612387f2454d6152920e09ee56..724840b6779cc5ceb56b73d56a2b206f3249ad50 100644 (file)
@@ -41,7 +41,8 @@ struct _PakfireFile {
        Pakfire pakfire;
        int nrefs;
 
-       char path[PATH_MAX];
+       const char* path;
+       char abspath[PATH_MAX];
        char type;
        ssize_t size;
 
@@ -236,8 +237,19 @@ PAKFIRE_EXPORT const char* pakfire_file_get_path(PakfireFile file) {
        return file->path;
 }
 
-PAKFIRE_EXPORT void pakfire_file_set_path(PakfireFile file, const char* path) {
-       snprintf(file->path, sizeof(file->path) - 1, "%s", path);
+PAKFIRE_EXPORT int pakfire_file_set_path(PakfireFile file, const char* path) {
+       char* p = pakfire_make_path(file->pakfire, path);
+       if (!p)
+               return 1;
+
+       // Copy to abspath
+       snprintf(file->abspath, sizeof(file->abspath) - 1, "%s", p);
+       free(p);
+
+       // Store relative path
+       file->path = file->abspath + strlen(file->abspath) - strlen(path);
+
+       return 0;
 }
 
 PAKFIRE_EXPORT char* pakfire_file_get_dirname(PakfireFile file) {
index 6c25abe06930704be6159a5603c3731759a7a021..20fd49489d72be3d425077f048941caeb09e53e2 100644 (file)
@@ -39,7 +39,7 @@ void pakfire_file_sprintf(PakfireFile file, char* str, size_t len);
 int pakfire_file_copy_stat(PakfireFile file, struct stat* stat);
 
 const char* pakfire_file_get_path(PakfireFile file);
-void pakfire_file_set_path(PakfireFile file, const char* path);
+int pakfire_file_set_path(PakfireFile file, const char* path);
 char* pakfire_file_get_dirname(PakfireFile file);
 char* pakfire_file_get_basename(PakfireFile file);