rspec->wim->chunk_size == out_chunk_size);
}
+ /* XXX: For compatibility, we can't allow multiple packed resources per
+ * WIM. */
+#if 0
if ((rspec->flags & WIM_RESHDR_FLAG_PACKED_STREAMS) &&
(write_resource_flags & WRITE_RESOURCE_FLAG_PACK_STREAMS))
{
return (write_size > rspec->uncompressed_size / 2);
}
+#endif
+
return false;
}
return 0;
}
+/* Rewrite a stream that was just written compressed as uncompressed instead.
+ * This function is optional, but if a stream did not compress to less than its
+ * original size, it might as well be written uncompressed. */
static int
write_stream_uncompressed(struct wim_lookup_table_entry *lte,
struct filedes *out_fd)
{
int ret;
+ u64 begin_offset = lte->out_reshdr.offset_in_wim;
+ u64 end_offset = out_fd->offset;
+
+ if (filedes_seek(out_fd, begin_offset) == -1)
+ return 0;
+
+ ret = extract_full_stream_to_fd(lte, out_fd);
+ if (ret) {
+ /* Error reading the uncompressed data. */
+ if (out_fd->offset == begin_offset &&
+ filedes_seek(out_fd, end_offset) != -1)
+ {
+ /* Nothing was actually written yet, and we successfully
+ * seeked to the end of the compressed resource, so
+ * don't issue a hard error; just keep the compressed
+ * resource instead. */
+ WARNING("Recovered compressed stream of "
+ "size %"PRIu64", continuing on.",
+ lte->size);
+ return 0;
+ }
+ return ret;
+ }
+
+ wimlib_assert(out_fd->offset - begin_offset == lte->size);
- if (-1 == lseek(out_fd->fd, lte->out_reshdr.offset_in_wim, SEEK_SET) ||
- 0 != ftruncate(out_fd->fd, lte->out_reshdr.offset_in_wim))
+ if (out_fd->offset < end_offset &&
+ 0 != ftruncate(out_fd->fd, out_fd->offset))
{
ERROR_WITH_ERRNO("Can't truncate output file to "
- "offset %"PRIu64, lte->out_reshdr.offset_in_wim);
+ "offset %"PRIu64, out_fd->offset);
return WIMLIB_ERR_WRITE;
}
- out_fd->offset = lte->out_reshdr.offset_in_wim;
-
- ret = extract_stream_to_fd(lte, out_fd, lte->size);
- if (ret)
- return ret;
-
- wimlib_assert(out_fd->offset - lte->out_reshdr.offset_in_wim == lte->size);
lte->out_reshdr.size_in_wim = lte->size;
lte->out_reshdr.flags &= ~(WIM_RESHDR_FLAG_COMPRESSED |
WIM_RESHDR_FLAG_PACKED_STREAMS);
if (ctx->cur_write_res_offset == ctx->cur_write_res_size &&
!(ctx->write_resource_flags & WRITE_RESOURCE_FLAG_PACK_STREAMS))
{
- struct wim_lookup_table_entry *lte;
-
- lte = list_entry(ctx->pending_streams.next,
- struct wim_lookup_table_entry, write_streams_list);
wimlib_assert(ctx->cur_write_res_offset == lte->size);
/* Finished writing a stream in non-packed mode. */
memcpy(&ctx->chunk_buf[ctx->chunk_buf_filled],
chunkptr, bytes_consumed);
- resized_chunk = ctx->chunk_buf;
-
chunkptr += bytes_consumed;
ctx->cur_read_res_offset += bytes_consumed;
ctx->chunk_buf_filled += bytes_consumed;
ctx.write_resource_flags = write_resource_flags;
ctx.filter_ctx = filter_ctx;
- if (out_chunk_size != 0) {
+ if (out_ctype != WIMLIB_COMPRESSION_TYPE_NONE) {
+ wimlib_assert(out_chunk_size != 0);
if (out_chunk_size <= STACK_MAX) {
ctx.chunk_buf = alloca(out_chunk_size);
} else {
&ctx.progress_data);
out_destroy_context:
- if (out_chunk_size > STACK_MAX)
+ if (out_ctype != WIMLIB_COMPRESSION_TYPE_NONE && out_chunk_size > STACK_MAX)
FREE(ctx.chunk_buf);
FREE(ctx.chunk_csizes);
if (ctx.compressor)
if (write_flags & WIMLIB_WRITE_FLAG_PACK_STREAMS)
DEBUG("\tPACK_STREAMS");
- if (write_flags & WIMLIB_WRITE_FLAG_NO_PACK_STREAMS)
- DEBUG("\tNO_PACK_STREAMS");
-
if (write_flags & WIMLIB_WRITE_FLAG_FILE_DESCRIPTOR)
DEBUG("\tFILE_DESCRIPTOR");
WIMLIB_WRITE_FLAG_NOT_PIPABLE))
return WIMLIB_ERR_INVALID_PARAM;
- if ((write_flags & (WIMLIB_WRITE_FLAG_PACK_STREAMS |
- WIMLIB_WRITE_FLAG_NO_PACK_STREAMS))
- == (WIMLIB_WRITE_FLAG_PACK_STREAMS |
- WIMLIB_WRITE_FLAG_NO_PACK_STREAMS))
- return WIMLIB_ERR_INVALID_PARAM;
-
/* Save previous header, then start initializing the new one. */
memcpy(&hdr_save, &wim->hdr, sizeof(struct wim_header));
write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
}
- if (!(write_flags & (WIMLIB_WRITE_FLAG_PACK_STREAMS |
- WIMLIB_WRITE_FLAG_NO_PACK_STREAMS)))
- if (wim->hdr.wim_version == WIM_VERSION_PACKED_STREAMS) {
- DEBUG("WIM version 3584; default to PACK_STREAMS.");
- write_flags |= WIMLIB_WRITE_FLAG_PACK_STREAMS;
- }
-
if ((write_flags & (WIMLIB_WRITE_FLAG_PIPABLE |
WIMLIB_WRITE_FLAG_PACK_STREAMS))
== (WIMLIB_WRITE_FLAG_PIPABLE |
if (wim_has_integrity_table(wim))
write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
- /* Set default packed flag. */
- if (!(write_flags & (WIMLIB_WRITE_FLAG_PACK_STREAMS |
- WIMLIB_WRITE_FLAG_NO_PACK_STREAMS)))
- {
- #if 0
- if (wim->hdr.wim_version == WIM_VERSION_PACKED_STREAMS)
- write_flags |= WIMLIB_WRITE_FLAG_PACK_STREAMS;
- #endif
- /* wimlib allows multiple packs in a single WIM, but they don't
- * seem to be compatible with WIMGAPI. Write new streams
- * unpacked. */
- } else if (write_flags & WIMLIB_WRITE_FLAG_PACK_STREAMS) {
+ /* Set WIM version if adding packed streams. */
+ if (write_flags & WIMLIB_WRITE_FLAG_PACK_STREAMS)
wim->hdr.wim_version = WIM_VERSION_PACKED_STREAMS;
- }
/* Set additional flags for overwrite. */
write_flags |= WIMLIB_WRITE_FLAG_OVERWRITE |