From: Michael Tremer Date: Wed, 17 Aug 2022 13:02:21 +0000 (+0000) Subject: file: Add function to return data as archive_entry X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5acd852e92ef7716158b0546ef058c7ae029d96c;p=people%2Fstevee%2Fpakfire.git file: Add function to return data as archive_entry Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index 1af0b661..47e03844 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -170,6 +170,46 @@ int pakfire_file_copy_archive_entry(struct pakfire_file* file, struct archive_en return r; } +struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file) { + 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 links + if (*file->hardlink) + archive_entry_set_hardlink(entry, file->hardlink); + if (*file->symlink) + archive_entry_set_symlink(entry, file->symlink); + + // Set size + archive_entry_set_size(entry, pakfire_file_get_size(file)); + + // Set mode + archive_entry_set_mode(entry, pakfire_file_get_mode(file)); + + // Set user + archive_entry_set_uname(entry, pakfire_file_get_user(file)); + + // Set group + archive_entry_set_gname(entry, pakfire_file_get_group(file)); + + // Set times + archive_entry_set_ctime(entry, pakfire_file_get_ctime(file), 0); + archive_entry_set_mtime(entry, pakfire_file_get_mtime(file), 0); + + // XXX copy digest + + return entry; +} + static void pakfire_file_free(struct pakfire_file* file) { struct pakfire_file_digest* digest = NULL; diff --git a/src/libpakfire/include/pakfire/file.h b/src/libpakfire/include/pakfire/file.h index 19a5375a..210b3dc0 100644 --- a/src/libpakfire/include/pakfire/file.h +++ b/src/libpakfire/include/pakfire/file.h @@ -81,6 +81,7 @@ struct pakfire_file* pakfire_file_parse_from_file(const char* list, unsigned int int pakfire_file_create_from_archive_entry(struct pakfire_file** file, struct pakfire* pakfire, struct archive_entry* entry); int pakfire_file_copy_archive_entry(struct pakfire_file* file, struct archive_entry* entry); +struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file); const char* pakfire_file_get_abspath(struct pakfire_file* file); int pakfire_file_set_abspath(struct pakfire_file* file, const char* path);