* count. */
memcpy(&hdr, &w->hdr, sizeof(struct wim_header));
+ /* Set image count and boot index correctly for single image writes */
+ if (image != WIMLIB_ALL_IMAGES) {
+ hdr.image_count = 1;
+ if (hdr.boot_idx == image)
+ hdr.boot_idx = 1;
+ else
+ hdr.boot_idx = 0;
+ }
+
+ /* In the WIM header, there is room for the resource entry for a
+ * metadata resource labeled as the "boot metadata". This entry should
+ * be zeroed out if there is no bootable image (boot_idx 0). Otherwise,
+ * it should be a copy of the resource entry for the image that is
+ * marked as bootable. This is not well documented... */
+ if (hdr.boot_idx == 0) {
+ memset(&hdr.boot_metadata_res_entry, 0,
+ sizeof(struct resource_entry));
+ } else {
+ memcpy(&hdr.boot_metadata_res_entry,
+ &w->image_metadata[
+ hdr.boot_idx - 1]->metadata_lte->output_resource_entry,
+ sizeof(struct resource_entry));
+ }
+
if (!(write_flags & WIMLIB_WRITE_FLAG_NO_LOOKUP_TABLE)) {
ret = write_lookup_table(w, image, &hdr.lookup_table_res_entry);
if (ret)
memset(&hdr.integrity, 0, sizeof(struct resource_entry));
}
- /*
- * In the WIM header, there is room for the resource entry for a
- * metadata resource labeled as the "boot metadata". This entry should
- * be zeroed out if there is no bootable image (boot_idx 0). Otherwise,
- * it should be a copy of the resource entry for the image that is
- * marked as bootable. This is not well documented...
- */
-
- /* Set image count and boot index correctly for single image writes */
- if (image != WIMLIB_ALL_IMAGES) {
- hdr.image_count = 1;
- if (hdr.boot_idx == image)
- hdr.boot_idx = 1;
- else
- hdr.boot_idx = 0;
- }
-
- if (hdr.boot_idx == 0) {
- memset(&hdr.boot_metadata_res_entry, 0,
- sizeof(struct resource_entry));
- } else {
- memcpy(&hdr.boot_metadata_res_entry,
- &w->image_metadata[
- hdr.boot_idx - 1]->metadata_lte->output_resource_entry,
- sizeof(struct resource_entry));
- }
-
if (fseeko(out, 0, SEEK_SET) != 0) {
ERROR_WITH_ERRNO("Failed to seek to beginning of WIM "
"being written");
}
out_close_wim:
if (fclose(out) != 0) {
- ERROR_WITH_ERRNO("Failed to close the WIM file");
+ ERROR_WITH_ERRNO("Failed to close the output WIM file");
if (ret == 0)
ret = WIMLIB_ERR_WRITE;
}
ret = begin_write(w, path, write_flags);
if (ret)
- goto out;
+ goto out_close_wim;
ret = write_wim_streams(w, image, write_flags, num_threads,
progress_func);
if (ret)
- goto out;
+ goto out_close_wim;
if (progress_func)
progress_func(WIMLIB_PROGRESS_MSG_WRITE_METADATA_BEGIN, NULL);
ret = for_image(w, image, write_metadata_resource);
if (ret)
- goto out;
+ goto out_close_wim;
if (progress_func)
progress_func(WIMLIB_PROGRESS_MSG_WRITE_METADATA_END, NULL);
ret = finish_write(w, image, write_flags, progress_func);
-out:
+ /* finish_write() closed the WIM for us */
+ goto out;
+out_close_wim:
close_wim_writable(w);
+out:
DEBUG("wimlib_write(path=%"TS") = %d", path, ret);
return ret;
}