Cleanup image export code
authorEric Biggers <ebiggers3@gmail.com>
Sun, 21 Oct 2012 16:54:58 +0000 (11:54 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 21 Oct 2012 16:54:58 +0000 (11:54 -0500)
src/join.c
src/lookup_table.h
src/modify.c
src/xml.c

index bf84efa503d96e7364725d423808d1986484c2be..f41cf047bc80ceb79f2bbd5450f8faa6f93d134a 100644 (file)
@@ -53,6 +53,23 @@ static int cmp_swms_by_part_number(const void *swm1, const void *swm2)
        return (int)partno_1 - (int)partno_2;
 }
 
+/*
+ * Sanity checks to make sure a set of WIMs correctly correspond to a spanned
+ * set.
+ *
+ * @w:
+ *     Part 1 of the set.
+ *
+ * @additional_swms:
+ *     All parts of the set other than part 1.
+ *
+ * @num_additional_swms:
+ *     Number of WIMStructs in @additional_swms.  Or, the total number of parts
+ *     in the set minus 1.
+ *
+ * @return:
+ *     0 on success; WIMLIB_ERR_SPLIT_INVALID if the set is not valid.
+ */
 int verify_swm_set(WIMStruct *w, WIMStruct **additional_swms,
                   unsigned num_additional_swms)
 {
@@ -63,8 +80,8 @@ int verify_swm_set(WIMStruct *w, WIMStruct **additional_swms,
        if (total_parts != num_additional_swms + 1) {
                ERROR("`%s' says there are %u parts in the spanned set, "
                      "but %s%u part%s provided",
-                     w->filename, w->hdr.total_parts,
-                     (num_additional_swms + 1 < w->hdr.total_parts) ? "only " : "",
+                     w->filename, total_parts,
+                     (num_additional_swms + 1 < total_parts) ? "only " : "",
                      num_additional_swms + 1,
                      (num_additional_swms) ? "s were" : " was");
                return WIMLIB_ERR_SPLIT_INVALID;
index 0017320c5e4a82f439005c05249346f20a0a1e14..5e4d1f5836d444dc8bd41ca29db8ad50cc9ea25a 100644 (file)
@@ -302,7 +302,7 @@ inode_stream_lte_resolved(const struct inode *inode, unsigned stream_idx)
 
 static inline struct lookup_table_entry *
 inode_stream_lte_unresolved(const struct inode *inode, unsigned stream_idx,
-                            const struct lookup_table *table)
+                           const struct lookup_table *table)
 {
        wimlib_assert(!inode->resolved);
        wimlib_assert(stream_idx <= inode->num_ads);
index dc55d5fa8534ffc5ff0fcf0e7580e0511666bbd3..f6886bbe1dcb32d2fb84f90095e29134e4d8211d 100644 (file)
@@ -240,11 +240,12 @@ struct wim_pair {
 
 /* 
  * This function takes in a dentry that was previously located only in image(s)
- * in @src_wim, but now is being added to @dest_wim. If there is in fact already a
- * lookup table entry for this file in the lookup table of the destination WIM
- * file, we simply increment its reference count.  Otherwise, a new lookup table
- * entry is created that references the location of the file resource in the
- * source WIM file through the other_wim_fp field of the lookup table entry.
+ * in @src_wim, but now is being added to @dest_wim.  For each stream associated
+ * with the dentry, if there is already a lookup table entry for that stream in
+ * the lookup table of the destination WIM file, its reference count is
+ * incrementej.  Otherwise, a new lookup table entry is created that points back
+ * to the stream in the source WIM file (through the @hash field combined with
+ * the @wim field of the lookup table entry.)
  */
 static int add_lte_to_dest_wim(struct dentry *dentry, void *arg)
 {
@@ -261,8 +262,10 @@ static int add_lte_to_dest_wim(struct dentry *dentry, void *arg)
                struct lookup_table_entry *src_lte, *dest_lte;
                src_lte = inode_stream_lte_unresolved(inode, i,
                                                      src_wim->lookup_table);
-               if (!src_lte)
+
+               if (!src_lte) /* Empty or nonexistent stream. */
                        continue;
+
                dest_lte = inode_stream_lte_unresolved(inode, i,
                                                       dest_wim->lookup_table);
                if (dest_lte) {
@@ -297,7 +300,9 @@ static int add_new_dentry_tree(WIMStruct *w, struct dentry *root_dentry,
        struct lookup_table_entry *metadata_lte;
        struct image_metadata *imd;
        struct image_metadata *new_imd;
-       struct link_group_table *lgt;
+       int ret;
+
+       wimlib_assert(root_dentry != NULL);
 
        DEBUG("Reallocating image metadata array for image_count = %u",
              w->hdr.image_count + 1);
@@ -330,8 +335,12 @@ static int add_new_dentry_tree(WIMStruct *w, struct dentry *root_dentry,
        w->image_metadata       = imd;
        w->hdr.image_count++;
 
-       /* Change the current image to the new one. */
-       return wimlib_select_image(w, w->hdr.image_count);
+       /* Change the current image to the new one.  There should not be any
+        * ways for this to fail, since the image is valid and the dentry tree
+        * is already in memory. */
+       ret = wimlib_select_image(w, w->hdr.image_count);
+       wimlib_assert(ret == 0);
+       return ret;
 out_free_metadata_lte:
        FREE(metadata_lte);
 out_free_imd:
@@ -399,8 +408,7 @@ WIMLIBAPI int wimlib_export_image(WIMStruct *src_wim,
                                        export_flags &= ~WIMLIB_EXPORT_FLAG_BOOT;
 
                                ret = wimlib_export_image(src_wim, i, dest_wim, 
-                                                         NULL,
-                                                         dest_description,
+                                                         NULL, NULL,
                                                          export_flags,
                                                          additional_swms,
                                                          num_additional_swms);
@@ -419,6 +427,13 @@ WIMLIBAPI int wimlib_export_image(WIMStruct *src_wim,
                      dest_name, src_image);
        }
 
+       if (!dest_description) {
+               dest_description = wimlib_get_image_description(src_wim,
+                                                               src_image);
+               DEBUG("Using description `%s' for source image %d",
+                     dest_description, src_image);
+       }
+
        DEBUG("Exporting image %d from `%s'", src_image, src_wim->filename);
 
        if (wimlib_image_name_in_use(dest_wim, dest_name)) {
@@ -449,11 +464,11 @@ WIMLIBAPI int wimlib_export_image(WIMStruct *src_wim,
        }
 
        /* Cleaning up here on failure would be hard.  For example, we could
-        * fail to allocate memory in add_lte_to_dest_wim(),
-        * leaving the lookup table entries in the destination WIM in an
-        * inconsistent state.  Until these issues can be resolved,
-        * wimlib_export_image() is documented as leaving dest_wim in an
-        * indeterminate state.  */
+        * fail to allocate memory in add_lte_to_dest_wim(), leaving the lookup
+        * table entries in the destination WIM in an inconsistent state.  Until
+        * these issues can be resolved, wimlib_export_image() is documented as
+        * leaving @dest_wim in an indeterminate state with the only permitted
+        * operation being wimlib_free().  */
        root = wim_root_dentry(src_wim);
        sd = wim_security_data(src_wim);
        for_dentry_in_tree(root, increment_dentry_refcnt, NULL);
index 2f80f7ef6276b1d87a16619909340e9ae75790bd..c377283751395b72392fbd11b5688adcf227a08f 100644 (file)
--- a/src/xml.c
+++ b/src/xml.c
@@ -818,6 +818,11 @@ static int clone_windows_info(const struct windows_info *old,
                return WIMLIB_ERR_NOMEM;
        if (old->system_root && !(new->system_root = STRDUP(old->system_root)))
                return WIMLIB_ERR_NOMEM;
+       if (old->windows_version_exists) {
+               new->windows_version_exists = true;
+               memcpy(&new->windows_version, &old->windows_version,
+                      sizeof(old->windows_version));
+       }
        return 0;
 }
 
@@ -876,7 +881,6 @@ int xml_export_image(const struct wim_info *old_wim_info,
 
        wimlib_assert(image >= 1 && image <= old_wim_info->num_images);
 
-
        if (*new_wim_info_p) {
                new_wim_info = *new_wim_info_p;
        } else {