// Archive Stuff
-int pakfire_archive_copy_data(struct archive* src, struct archive* dst);
+int pakfire_archive_copy_data(struct pakfire* pakfire,
+ struct archive* src, struct archive* dst);
int pakfire_archive_copy_data_to_buffer(struct pakfire* pakfire, struct archive* a,
struct archive_entry* entry, char** data, size_t* data_size);
// Copy payload
if (archive_entry_filetype(entry) == AE_IFREG) {
- r = pakfire_archive_copy_data(reader, a);
+ r = pakfire_archive_copy_data(pakfire, reader, a);
if (r) {
ERROR(pakfire, "Could not copy %s\n", archive_entry_pathname(entry));
-
- const char* error = archive_error_string(reader);
- if (error)
- ERROR(pakfire, "Read error: %s\n", error);
-
- error = archive_error_string(a);
- if (error)
- ERROR(pakfire, "Write error: %s\n", error);
-
goto ERROR;
}
}
// Archive Stuff
-int pakfire_archive_copy_data(struct archive* src, struct archive* dst) {
- const void* buffer;
- size_t size;
- off_t offset;
+int pakfire_archive_copy_data(struct pakfire* pakfire,
+ struct archive* src, struct archive* dst) {
+ const void* buffer = NULL;
+ size_t size = 0;
+ off_t offset = 0;
+
int r;
for (;;) {
// Read a block of data
r = archive_read_data_block(src, &buffer, &size, &offset);
+
+ // Exit if we have read everything from source
if (r == ARCHIVE_EOF)
return ARCHIVE_OK;
- else if (r)
+
+ // Catch any reading errors
+ else if (r) {
+ ERROR(pakfire, "Read error: %s\n", archive_error_string(src));
return r;
+ }
// Write the read block of data
r = archive_write_data(dst, buffer, size);
- if (r < 0)
+ if (r < 0) {
+ ERROR(pakfire, "Write error: %s\n", archive_error_string(dst));
return r;
+ }
}
}