- if (old->languages) {
- new->languages = CALLOC(old->num_languages, sizeof(new->languages[0]));
- if (!new->languages)
- return WIMLIB_ERR_NOMEM;
- new->num_languages = old->num_languages;
- for (size_t i = 0; i < new->num_languages; i++) {
- if (!old->languages[i])
- continue;
- new->languages[i] = STRDUP(old->languages[i]);
- if (!new->languages[i])
- return WIMLIB_ERR_NOMEM;
- }
- }
- if (old->default_language &&
- !(new->default_language = STRDUP(old->default_language)))
- return WIMLIB_ERR_NOMEM;
- if (old->system_root && !(new->system_root = STRDUP(old->system_root)))
+/*
+ * Update the DIRCOUNT, FILECOUNT, TOTALBYTES, HARDLINKBYTES, and
+ * LASTMODIFICATIONTIME elements for the specified WIM image.
+ *
+ * Note: since these stats are likely to be used for display purposes only, we
+ * no longer attempt to duplicate WIMGAPI's weird bugs when calculating them.
+ */
+int
+xml_update_image_info(WIMStruct *wim, int image)
+{
+ const struct wim_image_metadata *imd = wim->image_metadata[image - 1];
+ xmlNode *image_node = wim->xml_info->images[image - 1];
+ const struct wim_inode *inode;
+ u64 dir_count = 0;
+ u64 file_count = 0;
+ u64 total_bytes = 0;
+ u64 hard_link_bytes = 0;
+ u64 size;
+ xmlNode *dircount_node;
+ xmlNode *filecount_node;
+ xmlNode *totalbytes_node;
+ xmlNode *hardlinkbytes_node;
+ xmlNode *lastmodificationtime_node;
+
+ image_for_each_inode(inode, imd) {
+ if (inode_is_directory(inode))
+ dir_count += inode->i_nlink;
+ else
+ file_count += inode->i_nlink;
+ size = inode_sum_stream_sizes(inode, wim->blob_table);
+ total_bytes += size * inode->i_nlink;
+ hard_link_bytes += size * (inode->i_nlink - 1);
+ }
+
+ dircount_node = new_element_with_u64(NULL, "DIRCOUNT", dir_count);
+ filecount_node = new_element_with_u64(NULL, "FILECOUNT", file_count);
+ totalbytes_node = new_element_with_u64(NULL, "TOTALBYTES", total_bytes);
+ hardlinkbytes_node = new_element_with_u64(NULL, "HARDLINKBYTES",
+ hard_link_bytes);
+ lastmodificationtime_node =
+ new_element_with_timestamp(NULL, "LASTMODIFICATIONTIME",
+ now_as_wim_timestamp());
+
+ if (unlikely(!dircount_node || !filecount_node || !totalbytes_node ||
+ !hardlinkbytes_node || !lastmodificationtime_node)) {
+ xmlFreeNode(dircount_node);
+ xmlFreeNode(filecount_node);
+ xmlFreeNode(totalbytes_node);
+ xmlFreeNode(hardlinkbytes_node);
+ xmlFreeNode(lastmodificationtime_node);