- if (w->hdr.total_parts != 1) {
- ERROR("Deleting an image from a split WIM is not supported.");
- return WIMLIB_ERR_SPLIT_UNSUPPORTED;
- }
-
- if (image == WIMLIB_ALL_IMAGES) {
- for (i = w->hdr.image_count; i >= 1; i--) {
- ret = wimlib_delete_image(w, i);
- if (ret != 0)
- return ret;
- }
- return 0;
- }
-
- if (!w->all_images_verified) {
- ret = wim_run_full_verifications(w);
- if (ret != 0)
- return ret;
- }
-
- DEBUG("Deleting image %d", image);
-
- /* Even if the dentry tree is not allocated, we must select it (and
- * therefore allocate it) so that we can decrement the reference counts
- * in the lookup table. */
- ret = select_wim_image(w, image);
- if (ret != 0)
+ /* Load the metadata for the image to be deleted. This is necessary
+ * because streams referenced by files in the image need to have their
+ * reference counts decremented. */
+ ret = select_wim_image(wim, image);
+ if (ret)