- if (!w->image_metadata) {
- ERROR("Failed to allocate memory for %u metadata structures",
- w->hdr.image_count);
- ret = WIMLIB_ERR_NOMEM;
- goto out_free_lookup_table;
- }
- w->current_image = 0;
-
- DEBUG("Looking for metadata resources in the lookup table.");
-
- /* Find the images in the WIM by searching the lookup table. */
- ret = for_lookup_table_entry(w->lookup_table,
- append_metadata_resource_entry, w);
-
- if (ret != 0)
- goto out_free_image_metadata;
-
- /* Make sure all the expected images were found. (We already have
- * returned false if *extra* images were found) */
- if (w->current_image != w->hdr.image_count &&
- w->hdr.part_number == 1)
- {
- ERROR("Only found %u images in WIM, but expected %u",
- w->current_image, w->hdr.image_count);
- ret = WIMLIB_ERR_IMAGE_COUNT;
- goto out_free_image_metadata;
- }
-
- /* Sort images by the position of their metadata resources. I'm
- * assuming that is what determines the other of the images in the WIM
- * file, rather than their order in the lookup table, which is random
- * because of hashing. */
- qsort(w->image_metadata, w->current_image,
- sizeof(struct image_metadata), sort_image_metadata_by_position);
-
- w->current_image = WIMLIB_NO_IMAGE;
-
- /* Read the XML data. */
- ret = read_xml_data(w->fp, &w->hdr.xml_res_entry,
- &w->xml_data, &w->wim_info);
-
- if (ret != 0)
- goto out_free_image_metadata;
-
- xml_num_images = wim_info_get_num_images(w->wim_info);
- if (xml_num_images != w->hdr.image_count) {
- ERROR("In the file `%s', there are %u <IMAGE> elements "
- "in the XML data,", in_wim_path, xml_num_images);
- ERROR("but %u images in the WIM! There must be exactly one "
- "<IMAGE> element per image.", w->hdr.image_count);
- ret = WIMLIB_ERR_IMAGE_COUNT;
- goto out_free_xml_data;
- }
-
- DEBUG("Done beginning read of WIM file `%s'.", in_wim_path);
- /*return 0;*/
-
- //
- // Everything is freed in wimlib_free() anyway, so no need to roll back
- // changes here.
- //
-out_free_xml_data:
- /*FREE(w->xml_data);*/
- /*w->xml_data = NULL;*/
- /*free_wim_info(w->wim_info);*/
- /*w->wim_info = NULL;*/
-out_free_image_metadata:
- /*FREE(w->image_metadata);*/
- /*w->image_metadata = NULL;*/
- /*w->current_image = WIMLIB_NO_IMAGE;*/
-out_free_lookup_table:
- /*free_lookup_table(w->lookup_table);*/
- /*w->lookup_table = NULL;*/
-out_close:
- /*fclose(w->fp);*/
- /*w->fp = NULL;*/
- return ret;
+ xml_num_images = wim_info_get_num_images(wim->wim_info);
+ if (xml_num_images != wim->hdr.image_count) {
+ ERROR("In the file `%"TS"', there are %u <IMAGE> elements "
+ "in the XML data,", wimfile, xml_num_images);
+ ERROR("but %u images in the WIM! There must be exactly one "
+ "<IMAGE> element per image.", wim->hdr.image_count);
+ return WIMLIB_ERR_IMAGE_COUNT;
+ }
+ DEBUG("Done beginning read of WIM file `%"TS"'.", wimfile);
+ }
+ return 0;