From: Michael Tremer Date: Fri, 19 Aug 2022 16:35:17 +0000 (+0000) Subject: file: Automatically set abspath if path isn't set X-Git-Tag: 0.9.28~415 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=520213e97bbec9ea581439aa94585e017288d1a2;p=pakfire.git file: Automatically set abspath if path isn't set Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/db.c b/src/libpakfire/db.c index 7b9bea4fc..095a3a47c 100644 --- a/src/libpakfire/db.c +++ b/src/libpakfire/db.c @@ -2049,7 +2049,6 @@ static int pakfire_db_load_file_digest(struct pakfire_db* db, struct pakfire_fil static int pakfire_db_load_file(struct pakfire_db* db, struct pakfire_filelist* filelist, sqlite3_stmt* stmt) { struct pakfire_file* file = NULL; - char abspath[PATH_MAX]; int r; // Create a new file object @@ -2062,13 +2061,6 @@ static int pakfire_db_load_file(struct pakfire_db* db, struct pakfire_filelist* if (path) pakfire_file_set_path(file, path); - // Abspath - r = pakfire_path(db->pakfire, abspath, "%s", path); - if (r) - goto ERROR; - - pakfire_file_set_abspath(file, abspath); - // Size size_t size = sqlite3_column_int64(stmt, 1); if (size) diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index d33102711..03bf36c5b 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -284,13 +284,27 @@ PAKFIRE_EXPORT const char* pakfire_file_get_path(struct pakfire_file* file) { } PAKFIRE_EXPORT int pakfire_file_set_path(struct pakfire_file* file, const char* path) { + int r; + // Check if path is set and absolute if (!path || *path != '/') { errno = EINVAL; return 1; } - return pakfire_string_set(file->path, path); + // Store path + r = pakfire_string_set(file->path, path); + if (r) + return r; + + // Set abspath if it isn't set, yet + if (!*file->abspath) { + r = pakfire_path(file->pakfire, file->abspath, "%s", path); + if (r) + return r; + } + + return r; } PAKFIRE_EXPORT const char* pakfire_file_get_hardlink(struct pakfire_file* file) {