]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
file: Automatically set abspath if path isn't set
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Aug 2022 16:35:17 +0000 (16:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Aug 2022 16:35:17 +0000 (16:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/db.c
src/libpakfire/file.c

index 7b9bea4fc8052bade901d57013df788b173a915c..095a3a47cf271a47dea7fb86997fe5e0df21d0a5 100644 (file)
@@ -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)
index d331027115280b729ff8f4e1c160c2a0987f1f5c..03bf36c5b76b680eb0274f4b2cc509cc088f2f83 100644 (file)
@@ -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) {