static int archive_extract(PakfireArchive archive, struct archive* a, const char* prefix) {
struct archive_entry* entry;
int r;
+ PakfireFile file;
+
+ // Reset the filelist
+ pakfire_filelist_clear(archive->filelist);
struct archive* ext = archive_write_disk_new();
break;
}
+ // Create a new file object
+ r = pakfire_file_create(&file);
+ if (r)
+ return r;
+
+ // Import attributes
+ r = pakfire_file_copy_archive_entry(file, entry);
+ if (r)
+ return r;
+
const char* archive_pathname = archive_entry_pathname(entry);
size_t size = archive_entry_size(entry);
free(h);
}
- char* hexdigest = NULL;
-
// Create file
r = archive_write_header(ext, entry);
if (r != ARCHIVE_OK) {
// Copy payload
if (size > 0) {
+ char* hexdigest = NULL;
+
r = archive_copy_data(archive, a, ext, &hexdigest);
if (r != ARCHIVE_OK)
break;
+
+ // Set checksum
+ if (hexdigest) {
+ pakfire_file_set_chksum(file, hexdigest);
+ free(hexdigest);
+ }
}
+ // Append file to filelist
+ r = pakfire_filelist_append(archive->filelist, file);
+ if (r)
+ break;
+
+ pakfire_file_unref(file);
+
// Commit to disk
r = archive_write_finish_entry(ext);
switch (r) {
break;
}
- if (hexdigest)
- free(hexdigest);
-
if (r != ARCHIVE_OK)
break;
}
}
// Nothing to do if the list is empty
- if (pakfire_filelist_is_empty(filelist))
+ if (pakfire_filelist_is_empty(filelist)) {
+ r = 0;
goto END;
+ }
const char* sql = "INSERT INTO files(pkg, name, size, type, config, datafile, mode, "
"user, 'group', hash1, mtime, capabilities) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
#include <tar.h>
#include <time.h>
+#include <archive_entry.h>
+
#include <pakfire/constants.h>
#include <pakfire/file.h>
#include <pakfire/private.h>
return 0;
}
+int pakfire_file_copy_archive_entry(PakfireFile file, struct archive_entry* entry) {
+ // Set name
+ pakfire_file_set_name(file, archive_entry_pathname(entry));
+
+ // Set size
+ pakfire_file_set_size(file, archive_entry_size(entry));
+
+ // Set mode
+ pakfire_file_set_mode(file, archive_entry_mode(entry));
+
+ // Set user
+ pakfire_file_set_user(file, archive_entry_uname(entry));
+
+ // Set group
+ pakfire_file_set_group(file, archive_entry_gname(entry));
+
+ // Set mtime
+ pakfire_file_set_time(file, archive_entry_mtime(entry));
+
+ return 0;
+}
+
static void pakfire_file_free(PakfireFile file) {
if (file->name)
free(file->name);
}
PAKFIRE_EXPORT int pakfire_filelist_append(PakfireFilelist list, PakfireFile file) {
+ if (!file)
+ return EINVAL;
+
// Check if we have any space left
if (list->size >= list->elements_size) {
int r = pakfire_filelist_grow(list, 64);
PakfireFile pakfire_file_parse_from_file(const char* list, unsigned int format);
+#ifdef PAKFIRE_PRIVATE
+
+#include <archive_entry.h>
+
+int pakfire_file_copy_archive_entry(PakfireFile file, struct archive_entry* entry);
+
+#endif
+
#endif /* PAKFIRE_FILE_H */