return r;
}
-PAKFIRE_EXPORT int pakfire_archive_extract(struct pakfire_archive* archive) {
+static int __pakfire_archive_extract(struct pakfire_archive* archive,
+ struct pakfire_filelist* filelist, int flags) {
struct pakfire_package* pkg = NULL;
struct archive* a = NULL;
struct archive* payload = NULL;
goto ERROR;
// Extract
- r = pakfire_extract(archive->pakfire, payload, size, prefix, nevra, 0);
+ r = pakfire_extract(archive->pakfire, payload, size, filelist, prefix, nevra, flags);
if (r)
goto ERROR;
return r;
}
+PAKFIRE_EXPORT int pakfire_archive_extract(struct pakfire_archive* archive) {
+ return __pakfire_archive_extract(archive, NULL, 0);
+}
+
PAKFIRE_EXPORT const char* pakfire_archive_get_path(struct pakfire_archive* archive) {
return archive->path;
}
return archive->format;
}
-static int pakfire_archive_load_filelist_mtree(struct pakfire_archive* archive) {
- struct archive* a;
- struct archive_entry* entry;
+static int pakfire_archive_load_filelist(struct pakfire_archive* archive) {
int r;
- // Find filelist
- r = open_archive_and_find(archive, &a, &entry, "FILELIST");
- if (r) {
- // Ignore if filelist doesn't exist
- if (errno == ENOENT)
- return 0;
-
- return r;
- }
-
- // Allocate a new archive reader
- struct archive* mtree = archive_read_new();
- if (!mtree) {
- ERROR(archive->pakfire, "Could not allocate mtree reader\n");
- goto ERROR;
- }
-
- // Enable reading the mtree format
- r = archive_read_support_format_mtree(mtree);
- if (r) {
- ERROR(archive->pakfire, "Could not enable mtree format: %s\n",
- archive_error_string(mtree));
- goto ERROR;
- }
-
- // Filelists can be Zstandard-compressed
- r = archive_read_support_filter_zstd(mtree);
- if (r)
- goto ERROR;
-
- // Try opening the mtree
- r = archive_read_open2(mtree, a, NULL, pakfire_archive_read_callback, NULL, NULL);
- if (r) {
- ERROR(archive->pakfire, "Could not open filelist mtree in %s: %s\n",
- archive->path, archive_error_string(mtree));
- goto ERROR;
- }
-
- // Read filelist
+ // Create a new filelist
r = pakfire_filelist_create(&archive->filelist, archive->pakfire);
if (r)
- goto ERROR;
-
- for (;;) {
- struct pakfire_file* file;
-
- r = archive_read_next_header(mtree, &entry);
- if (r == ARCHIVE_EOF) {
- r = 0;
- break;
- } else if (r)
- goto ERROR;
-
- // Create a new file object
- r = pakfire_file_create_from_archive_entry(&file, archive->pakfire, entry);
- if (r)
- goto ERROR;
-
- // Append to filelist
- r = pakfire_filelist_append(archive->filelist, file);
- pakfire_file_unref(file);
- if (r)
- goto ERROR;
- }
-
-ERROR:
- // Destroy the filelist on error
- if (r && archive->filelist) {
- pakfire_filelist_unref(archive->filelist);
- archive->filelist = NULL;
- }
-
- if (mtree)
- archive_read_free(mtree);
- close_archive(archive, a);
-
- return r;
-}
-
-static int pakfire_archive_load_filelist_legacy(struct pakfire_archive* archive) {
- char* data = NULL;
- size_t size;
-
- // Read filelist
- int r = open_archive_and_read(archive, "FILELIST", &data, &size);
- if (r) {
- if (errno == ENOENT)
- return 0;
-
return r;
- }
-
- DEBUG(archive->pakfire, "Read filelist:\n%.*s\n", (int)size, data);
- r = pakfire_filelist_create_from_file(&archive->filelist,
- archive->pakfire, data, archive->format);
- if (r)
- ERROR(archive->pakfire, "Could not parse filelist: %m\n");
-
- if (data)
- free(data);
-
- // Destroy the filelist on error
- if (r && archive->filelist) {
+ // Peform a dry-run extraction
+ r = __pakfire_archive_extract(archive, archive->filelist,
+ PAKFIRE_EXTRACT_DRY_RUN|PAKFIRE_EXTRACT_NO_PROGRESS);
+ if (r) {
+ // Free the incomplete filelist on error
pakfire_filelist_unref(archive->filelist);
archive->filelist = NULL;
}
return r;
}
-static int pakfire_archive_load_filelist(struct pakfire_archive* archive) {
- if (archive->format >= 6)
- return pakfire_archive_load_filelist_mtree(archive);
- else
- return pakfire_archive_load_filelist_legacy(archive);
-}
-
PAKFIRE_EXPORT struct pakfire_filelist* pakfire_archive_get_filelist(struct pakfire_archive* archive) {
if (!archive->filelist) {
int r = pakfire_archive_load_filelist(archive);