+ DEBUG("Using description \"%"TS"\"", next_dest_description);
+
+ /* Check for name conflict. */
+ if (wimlib_image_name_in_use(dest_wim, next_dest_name)) {
+ ERROR("There is already an image named \"%"TS"\" "
+ "in the destination WIM", next_dest_name);
+ ret = WIMLIB_ERR_IMAGE_NAME_COLLISION;
+ goto out_rollback;
+ }
+
+ /* Load metadata for source image into memory. */
+ ret = select_wim_image(src_wim, image);
+ if (ret)
+ goto out_rollback;
+
+ src_imd = wim_get_current_image_metadata(src_wim);
+
+ /* Iterate through inodes in the source image and export their
+ * streams into the destination WIM. */
+ image_for_each_inode(inode, src_imd) {
+ ret = inode_export_streams(inode,
+ src_wim->lookup_table,
+ dest_wim->lookup_table,
+ export_flags & WIMLIB_EXPORT_FLAG_GIFT);
+ if (ret)
+ goto out_rollback;
+ }
+
+ /* Export XML information into the destination WIM. */
+ ret = xml_export_image(src_wim->wim_info, image,
+ &dest_wim->wim_info, next_dest_name,
+ next_dest_description);
+ if (ret)
+ goto out_rollback;
+
+ /* Reference the source image metadata from the destination WIM.
+ */
+ ret = append_image_metadata(dest_wim, src_imd);
+ if (ret)
+ goto out_rollback;
+ src_imd->refcnt++;
+
+ /* Lock the metadata into memory. XXX: need better solution for
+ * this. */
+ src_imd->modified = 1;
+
+ /* Set boot index in destination WIM. */
+ if ((export_flags & WIMLIB_EXPORT_FLAG_BOOT) &&
+ (src_image != WIMLIB_ALL_IMAGES ||
+ image == src_wim->hdr.boot_idx))
+ {
+ DEBUG("Marking destination image %u as bootable.",
+ dest_wim->hdr.image_count);
+ dest_wim->hdr.boot_idx = dest_wim->hdr.image_count;
+ }
+
+ /* Possibly set WIMBoot flag */
+ if (export_flags & WIMLIB_EXPORT_FLAG_WIMBOOT) {
+ wim_info_set_wimboot(dest_wim->wim_info,
+ dest_wim->hdr.image_count,
+ true);
+ }