From: Michael Tremer Date: Mon, 8 Mar 2021 22:04:45 +0000 (+0000) Subject: file: Store the absolute path X-Git-Tag: 0.9.28~1285^2~601 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0027da6f26819ab3d4bc02dfc137c2b2ccfe46a6;p=pakfire.git file: Store the absolute path Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index 6aeb46e14..724840b67 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -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) { diff --git a/src/libpakfire/include/pakfire/file.h b/src/libpakfire/include/pakfire/file.h index 6c25abe06..20fd49489 100644 --- a/src/libpakfire/include/pakfire/file.h +++ b/src/libpakfire/include/pakfire/file.h @@ -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);