- /* Pre-allocate the new lookup table entries that will be needed. This
- * way, it's not possible to run out of memory part-way through
- * modifying the lookup table of the destination WIM. */
- wims.src_wim = src_wim;
- wims.dest_wim = dest_wim;
- INIT_LIST_HEAD(&wims.lte_list_head);
- for_lookup_table_entry(src_wim->lookup_table, lte_zero_out_refcnt, NULL);
- root = wim_root_dentry(src_wim);
- for_dentry_in_tree(root, dentry_unresolve_ltes, NULL);
- ret = for_dentry_in_tree(root, allocate_lte_if_needed, &wims);
- if (ret != 0)
- goto out_free_ltes;
-
- ret = xml_export_image(src_wim->wim_info, src_image,
- &dest_wim->wim_info, dest_name, dest_description);
- if (ret != 0)
- goto out_free_ltes;
-
- sd = wim_security_data(src_wim);
- ret = add_new_dentry_tree(dest_wim, root, sd);
- if (ret != 0)
- goto out_xml_delete_image;
-
-
- /* All memory allocations have been taken care of, so it's no longer
- * possible for this function to fail. Go ahead and increment the
- * reference counts of the dentry tree and security data, then update
- * the lookup table of the destination WIM and the boot index, if
- * needed. */
- for_dentry_in_tree(root, increment_dentry_refcnt, NULL);
- sd->refcnt++;
- for_dentry_in_tree(root, add_lte_to_dest_wim, &wims);
- wimlib_assert(list_empty(&wims.lte_list_head));
-
- if (export_flags & WIMLIB_EXPORT_FLAG_BOOT) {
- DEBUG("Setting boot_idx to %d", dest_wim->hdr.image_count);
- wimlib_set_boot_idx(dest_wim, dest_wim->hdr.image_count);