- new_compressed_size = old_compressed_size;
- }
-
- if (!raw) {
- u8 md[SHA1_HASH_SIZE];
- sha1_final(md, &ctx);
- if (!hashes_equal(md, lte->hash)) {
- ERROR("WIM resource has incorrect hash!");
- if (lte->resource_location == RESOURCE_IN_FILE_ON_DISK) {
- ERROR("We were reading it from `%s'; maybe it changed "
- "while we were reading it.",
- lte->file_on_disk);
- }
- ret = WIMLIB_ERR_INTEGRITY;
- goto out_fclose;
- }
- }
-
- if (new_compressed_size > original_size) {
- /* Oops! We compressed the resource to larger than the original
- * size. Write the resource uncompressed instead. */
- if (fseeko(out_fp, file_offset, SEEK_SET) != 0) {
- ERROR_WITH_ERRNO("Failed to seek to byte "PRIu64" "
- "of output WIM file", file_offset);
- ret = WIMLIB_ERR_WRITE;
- goto out_fclose;
- }
- ret = write_wim_resource(lte, out_fp, WIM_COMPRESSION_TYPE_NONE,
- out_res_entry);
- if (ret != 0)
- goto out_fclose;
- if (fflush(out_fp) != 0) {
- ERROR_WITH_ERRNO("Failed to flush output WIM file");
- ret = WIMLIB_ERR_WRITE;
- goto out_fclose;
- }
- if (ftruncate(fileno(out_fp), file_offset + out_res_entry->size) != 0) {
- ERROR_WITH_ERRNO("Failed to truncate output WIM file");
- ret = WIMLIB_ERR_WRITE;
- }
- goto out_fclose;
- }
- wimlib_assert(new_compressed_size <= original_size);
- if (out_res_entry) {
- out_res_entry->size = new_compressed_size;
- out_res_entry->original_size = original_size;
- out_res_entry->offset = file_offset;
- if (out_ctype == WIM_COMPRESSION_TYPE_NONE)
- out_res_entry->flags = 0;
- else
- out_res_entry->flags = WIM_RESHDR_FLAG_COMPRESSED;
- if (lte->resource_entry.flags & WIM_RESHDR_FLAG_METADATA)
- out_res_entry->flags |= WIM_RESHDR_FLAG_METADATA;
- }
-out_fclose:
- if (lte->resource_location == RESOURCE_IN_FILE_ON_DISK
- && lte->file_on_disk_fp) {
- fclose(lte->file_on_disk_fp);
- lte->file_on_disk_fp = NULL;