// Prefix
const char* prefix;
- // Flags
- int flags;
+ // Writer
+ struct archive* writer;
};
static void pakfire_extract_progress(void* data) {
}
}
- // We are done if we are running in dry-run mode
- if (state->flags & PAKFIRE_EXTRACT_DRY_RUN)
- goto ERROR;
-
- struct archive* writer = pakfire_get_disk_writer(archive->pakfire);
-
- // Fetch path again since we changed it
- path = archive_entry_pathname(entry);
+ // Write the file...
+ if (state->writer) {
+ // Fetch path again since we changed it
+ path = archive_entry_pathname(entry);
- CTX_DEBUG(ctx, "Extracting %s\n", path);
+ CTX_DEBUG(ctx, "Extracting %s\n", path);
- // Remove any extended attributes which we never write to disk
- archive_entry_xattr_clear(entry);
+ // Remove any extended attributes which we never write to disk
+ archive_entry_xattr_clear(entry);
- // Set capabilities
- if (pakfire_file_has_caps(file)) {
- r = pakfire_file_write_fcaps(file, &cap_data);
- if (r)
- goto ERROR;
+ // Set capabilities
+ if (pakfire_file_has_caps(file)) {
+ r = pakfire_file_write_fcaps(file, &cap_data);
+ if (r)
+ goto ERROR;
- // Store capabilities in archive entry
- archive_entry_xattr_add_entry(entry,
- "security.capability", &cap_data, sizeof(cap_data));
- }
+ // Store capabilities in archive entry
+ archive_entry_xattr_add_entry(entry,
+ "security.capability", &cap_data, sizeof(cap_data));
+ }
- // Write payload
- r = archive_read_extract2(state->a, entry, writer);
- switch (r) {
- case ARCHIVE_OK:
- r = 0;
- break;
+ // Write payload
+ r = archive_read_extract2(state->a, entry, state->writer);
+ switch (r) {
+ case ARCHIVE_OK:
+ r = 0;
+ break;
- case ARCHIVE_WARN:
- CTX_ERROR(ctx, "%s\n", archive_error_string(writer));
+ case ARCHIVE_WARN:
+ CTX_ERROR(ctx, "%s\n", archive_error_string(state->writer));
- // Pretend everything has been okay
- r = 0;
- break;
+ // Pretend everything has been okay
+ r = 0;
+ break;
- case ARCHIVE_FATAL:
- CTX_ERROR(ctx, "%s\n", archive_error_string(writer));
- r = 1;
- break;
+ case ARCHIVE_FATAL:
+ CTX_ERROR(ctx, "%s\n", archive_error_string(state->writer));
+ r = 1;
+ break;
+ }
}
ERROR:
static int __pakfire_archive_extract(struct pakfire_archive* archive, const char* path, int flags) {
struct pakfire_package* pkg = NULL;
char prefix[PATH_MAX] = "/";
+ struct archive* writer = NULL;
struct archive* a = NULL;
int r;
goto ERROR;
}
+ // Setup the writer if we are not running in dry mode
+ if (!(flags & PAKFIRE_EXTRACT_DRY_RUN)) {
+ writer = pakfire_get_disk_writer(archive->pakfire);
+ if (!writer) {
+ r = -errno;
+ goto ERROR;
+ }
+ }
+
// Fetch NEVRA
const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
.archive = archive,
.a = a,
.prefix = prefix,
- .flags = flags,
+ .writer = writer,
};
// Register progress callback