struct pakfire_archive_extractor {
struct archive* writer;
const char* path;
- PakfireFilelist filelist;
struct pakfire_progressbar* progressbar;
};
struct archive* a, struct archive_entry* entry, void* data) {
struct pakfire_archive_extractor* extractor = (struct pakfire_archive_extractor*)data;
- PakfireFile file = NULL;
char buffer[PATH_MAX];
int r = 1;
if (extractor->progressbar)
pakfire_progressbar_update(extractor->progressbar, bytes_read);
- // Create a new file object if there is a filelist
- if (extractor->filelist) {
- r = pakfire_file_create(&file, archive->pakfire);
- if (r)
- goto ERROR;
-
- // Import attributes
- r = pakfire_file_copy_archive_entry(file, entry);
- if (r)
- goto ERROR;
-
- // Append it to the filelist
- r = pakfire_filelist_append(extractor->filelist, file);
- if (r)
- goto ERROR;
- }
-
// Fetch the paths
const char* path = archive_entry_pathname(entry);
if (extractor->path && *extractor->path) {
r = pakfire_path_join(buffer, extractor->path, path);
if (r < 0)
- goto ERROR;
+ return r;
archive_entry_set_pathname(entry, buffer);
if (link) {
r = pakfire_path_join(buffer, extractor->path, link);
if (r < 0)
- goto ERROR;
+ return r;
archive_entry_set_hardlink(entry, buffer);
}
case ARCHIVE_FATAL:
ERROR(archive->pakfire, "Could not extract file %s: %s\n",
path, archive_error_string(extractor->writer));
- goto ERROR;
+ return 1;
}
-ERROR:
- if (file)
- pakfire_file_unref(file);
-
- return r;
+ return 0;
}
PAKFIRE_EXPORT int pakfire_archive_extract(PakfireArchive archive, const char* prefix) {
DEBUG(archive->pakfire, "Extracting %s to %s\n", archive->path, path);
- // Create a filelist
- if (!archive->filelist) {
- r = pakfire_filelist_create(&archive->filelist, archive->pakfire);
- if (r)
- goto ERROR;
- }
-
// Create a progressbar
r = pakfire_archive_extract_progressbar(archive, &progressbar);
if (r)
struct pakfire_archive_extractor extractor = {
.writer = writer,
.path = path,
- .filelist = archive->filelist,
.progressbar = progressbar,
};
if (progressbar)
pakfire_progressbar_finish(progressbar);
- // Destroy the filelist on error
- if (r) {
- pakfire_filelist_unref(archive->filelist);
- archive->filelist = NULL;
- }
-
if (progressbar)
pakfire_progressbar_unref(progressbar);
if (writer)