- /* Fill in out_reshdr with information about the newly written
- * resource. */
- out_reshdr->size_in_wim = out_fd->offset - res_start_offset;
- out_reshdr->flags = lte->flags;
- if (out_ctype == WIMLIB_COMPRESSION_TYPE_NONE)
- out_reshdr->flags &= ~WIM_RESHDR_FLAG_COMPRESSED;
- else
- out_reshdr->flags |= WIM_RESHDR_FLAG_COMPRESSED;
- out_reshdr->offset_in_wim = res_start_offset;
- out_reshdr->uncompressed_size = lte->size;
-
- /* Check for resources compressed to greater than their original size
- * and write them uncompressed instead. (But never do this if writing
- * to a pipe, and don't bother if we did a raw copy.) */
- if (out_reshdr->size_in_wim > out_reshdr->uncompressed_size &&
- !(resource_flags & (WIMLIB_WRITE_RESOURCE_FLAG_PIPABLE |
- WIMLIB_READ_RESOURCE_FLAG_RAW)))
- {
- DEBUG("Compressed %"PRIu64" => %"PRIu64" bytes; "
- "writing uncompressed instead",
- out_reshdr->uncompressed_size, out_reshdr->size_in_wim);
- ret = seek_and_truncate(out_fd, res_start_offset);
- if (ret)
- goto out_free_chunk_tab;
- out_ctype = WIMLIB_COMPRESSION_TYPE_NONE;
- FREE(write_ctx.chunk_tab);
- write_ctx.out_ctype = WIMLIB_COMPRESSION_TYPE_NONE;
- write_ctx.chunk_tab = NULL;
- write_ctx.doing_sha = false;
- goto try_write_again;
- }
- if (resource_flags & WIMLIB_READ_RESOURCE_FLAG_RAW) {
- DEBUG("Copied raw compressed data "
- "(%"PRIu64" => %"PRIu64" bytes @ +%"PRIu64", flags=0x%02x)",
- out_reshdr->uncompressed_size, out_reshdr->size_in_wim,
- out_reshdr->offset_in_wim, out_reshdr->flags);
- } else if (out_ctype != WIMLIB_COMPRESSION_TYPE_NONE) {
- DEBUG("Wrote compressed resource "
- "(%"PRIu64" => %"PRIu64" bytes @ +%"PRIu64", flags=0x%02x)",
- out_reshdr->uncompressed_size, out_reshdr->size_in_wim,
- out_reshdr->offset_in_wim, out_reshdr->flags);
- } else {
- DEBUG("Wrote uncompressed resource "
- "(%"PRIu64" bytes @ +%"PRIu64", flags=0x%02x)",
- out_reshdr->uncompressed_size,
- out_reshdr->offset_in_wim, out_reshdr->flags);
- }
- ret = 0;
-out_free_chunk_tab:
- FREE(write_ctx.chunk_tab);
-out:
- return ret;