From: Michael Tremer Date: Mon, 5 Sep 2022 16:03:30 +0000 (+0000) Subject: file: Try to be smarter and set abspath/path automatically X-Git-Tag: 0.9.28~323 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49a39ad96a0cfdcbf4900c0505d2438e9f55e12d;p=pakfire.git file: Try to be smarter and set abspath/path automatically Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index 2fe7195b7..56a85a716 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -86,20 +86,30 @@ struct pakfire_file { }; static int pakfire_file_from_archive_entry(struct pakfire_file* file, struct archive_entry* entry) { + const char* path = NULL; const char* attr = NULL; const void* value = NULL; size_t size = 0; int r = 0; // Set abspath - r = pakfire_file_set_abspath(file, archive_entry_sourcepath(entry)); - if (r) { - ERROR(file->pakfire, "Could not set abspath: %m\n"); - goto ERROR; + path = archive_entry_sourcepath(entry); + if (path) { + // Make path absolute + path = pakfire_path_abspath(path); + if (!path) + goto ERROR; + + // Set + r = pakfire_file_set_abspath(file, path); + if (r) { + ERROR(file->pakfire, "Could not set abspath: %m\n"); + goto ERROR; + } } // Set path - const char* path = archive_entry_pathname(entry); + path = archive_entry_pathname(entry); if (path) { // Strip any leading dots from paths if (pakfire_string_startswith(path, "./")) @@ -260,19 +270,19 @@ ERROR: return r; } -struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file) { +struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file, int digest_types) { struct archive_entry* entry = archive_entry_new(); if (!entry) { ERROR(file->pakfire, "Could not allocate archive entry: %m\n"); return NULL; } - // Set path - archive_entry_copy_pathname(entry, pakfire_file_get_path(file)); - // Set source path archive_entry_copy_sourcepath(entry, file->abspath); + // Set path + archive_entry_copy_pathname(entry, pakfire_file_get_path(file)); + // Set links if (*file->hardlink) archive_entry_set_hardlink(entry, file->hardlink); @@ -367,13 +377,31 @@ const char* pakfire_file_get_abspath(struct pakfire_file* file) { } int pakfire_file_set_abspath(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->abspath, path); + // Store the abspath + r = pakfire_string_set(file->abspath, path); + if (r) + goto ERROR; + + // Store path if it isn't set, yet + if (!*file->path) { + r = pakfire_file_set_path(file, path); + if (r) + goto ERROR; + } + + return r; + +ERROR: + ERROR(file->pakfire, "Could not set abspath '%s': %m\n", path); + return r; } PAKFIRE_EXPORT const char* pakfire_file_get_path(struct pakfire_file* file) {