]> wimlib.net Git - wimlib/blobdiff - src/write.c
Delay xml_update_image_info() until write
[wimlib] / src / write.c
index 0a899945620acd59f04ddc6239fb2d37abdebd91..23dda573a3aff33e63836ae843ea2629eaf543c5 100644 (file)
@@ -2639,6 +2639,25 @@ should_default_to_solid_compression(WIMStruct *wim, int write_flags)
                wim_has_solid_resources(wim);
 }
 
+/* Update the images' filecount/bytecount stats (in the XML info) to take into
+ * account any recent modifications.  */
+static int
+update_image_stats(WIMStruct *wim)
+{
+       if (!wim_has_metadata(wim))
+               return 0;
+       for (int i = 0; i < wim->hdr.image_count; i++) {
+               struct wim_image_metadata *imd = wim->image_metadata[i];
+               if (imd->stats_outdated) {
+                       int ret = xml_update_image_info(wim, i + 1);
+                       if (ret)
+                               return ret;
+                       imd->stats_outdated = false;
+               }
+       }
+       return 0;
+}
+
 /* Write a standalone WIM or split WIM (SWM) part to a new file or to a file
  * descriptor.  */
 int
@@ -2786,6 +2805,11 @@ write_wim_part(WIMStruct *wim,
                        wim->out_hdr.boot_idx = 1;
        }
 
+       /* Update image stats if needed.  */
+       ret = update_image_stats(wim);
+       if (ret)
+               return ret;
+
        /* Set up the output file descriptor.  */
        if (write_flags & WIMLIB_WRITE_FLAG_FILE_DESCRIPTOR) {
                /* File descriptor was explicitly provided.  */
@@ -3130,6 +3154,11 @@ overwrite_wim_inplace(WIMStruct *wim, int write_flags, unsigned num_threads)
                        wimlib_assert(list_empty(&blob_list));
        }
 
+       /* Update image stats if needed.  */
+       ret = update_image_stats(wim);
+       if (ret)
+               goto out;
+
        ret = open_wim_writable(wim, wim->filename, O_RDWR);
        if (ret)
                goto out;