Add WIMLIB_WRITE_FLAG_RETAIN_GUID
authorEric Biggers <ebiggers3@gmail.com>
Wed, 14 May 2014 18:37:57 +0000 (13:37 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Wed, 14 May 2014 20:46:29 +0000 (15:46 -0500)
... and use it in wimlib_join() and wimlib_overwrite().

Remove the guid_set_explicitly hack.

include/wimlib.h
include/wimlib/wim.h
include/wimlib/write.h
src/join.c
src/wim.c
src/write.c

index 0684d62..52c9542 100644 (file)
@@ -1737,7 +1737,10 @@ typedef int (*wimlib_iterate_lookup_table_callback_t)(const struct wimlib_resour
  * already implied for wimlib_overwrite().  */
 #define WIMLIB_WRITE_FLAG_STREAMS_OK                   0x00000400
 
-#define WIMLIB_WRITE_FLAG_RESERVED                     0x00000800
+/** For wimlib_write() and wimlib_write_to_fd(), retain the same GUID instead of
+ * generating a new one.  This is already the default for wimlib_overwrite().
+ */
+#define WIMLIB_WRITE_FLAG_RETAIN_GUID                  0x00000800
 
 /**
  * When writing streams in the resulting WIM file, pack multiple streams into a
index 42d109e..ea916aa 100644 (file)
@@ -68,8 +68,6 @@ struct WIMStruct {
 
        u8 wim_locked : 1;
 
-       u8 guid_set_explicitly : 1;
-
        /* One of WIMLIB_COMPRESSION_TYPE_*, cached from the header flags. */
        u8 compression_type;
 
index 190bf94..7e913e1 100644 (file)
@@ -27,7 +27,7 @@
        WIMLIB_WRITE_FLAG_IGNORE_READONLY_FLAG          | \
        WIMLIB_WRITE_FLAG_SKIP_EXTERNAL_WIMS            | \
        WIMLIB_WRITE_FLAG_STREAMS_OK                    | \
-       WIMLIB_WRITE_FLAG_RESERVED                      | \
+       WIMLIB_WRITE_FLAG_RETAIN_GUID                   | \
        WIMLIB_WRITE_FLAG_PACK_STREAMS)
 
 #if defined(HAVE_SYS_FILE_H) && defined(HAVE_FLOCK)
index f61eaaf..71e43c0 100644 (file)
@@ -203,13 +203,13 @@ wimlib_join(const tchar * const *swm_names,
        if (ret)
                goto out_free_swms;
 
-       swm0->guid_set_explicitly = 1;
-
        /* It is reasonably safe to provide, WIMLIB_WRITE_FLAG_STREAMS_OK, as we
         * have verified that the specified split WIM parts form a spanned set.
         */
        ret = wimlib_write(swm0, output_path, WIMLIB_ALL_IMAGES,
-                          wim_write_flags | WIMLIB_WRITE_FLAG_STREAMS_OK,
+                          wim_write_flags |
+                               WIMLIB_WRITE_FLAG_STREAMS_OK |
+                               WIMLIB_WRITE_FLAG_RETAIN_GUID,
                           1, progress_func);
 out_free_swms:
        for (i = 0; i < num_additional_swms + 1; i++)
index 2d788b0..960a9d5 100644 (file)
--- a/src/wim.c
+++ b/src/wim.c
@@ -512,10 +512,8 @@ wimlib_set_wim_info(WIMStruct *wim, const struct wimlib_wim_info *info, int whic
        if (ret)
                return ret;
 
-       if (which & WIMLIB_CHANGE_GUID) {
+       if (which & WIMLIB_CHANGE_GUID)
                memcpy(wim->hdr.guid, info->guid, WIM_GUID_LEN);
-               wim->guid_set_explicitly = 1;
-       }
 
        if (which & WIMLIB_CHANGE_BOOT_INDEX) {
                if (info->boot_index > wim->hdr.image_count) {
index e7888cd..f34481a 100644 (file)
@@ -2595,6 +2595,9 @@ write_wim_part(WIMStruct *wim,
        if (write_flags & WIMLIB_WRITE_FLAG_STREAMS_OK)
                DEBUG("\tSTREAMS_OK");
 
+       if (write_flags & WIMLIB_WRITE_FLAG_RETAIN_GUID)
+               DEBUG("\tRETAIN_GUID");
+
        if (write_flags & WIMLIB_WRITE_FLAG_PACK_STREAMS)
                DEBUG("\tPACK_STREAMS");
 
@@ -2613,8 +2616,9 @@ write_wim_part(WIMStruct *wim,
                DEBUG("Number of threads: %u", num_threads);
        DEBUG("Progress function: %s", (progress_func ? "yes" : "no"));
        DEBUG("Stream list:       %s", (stream_list_override ? "specified" : "autodetect"));
-       DEBUG("GUID:              %s", ((guid || wim->guid_set_explicitly) ?
-                                       "specified" : "generate new"));
+       DEBUG("GUID:              %s", (guid ||
+                                       (write_flags & WIMLIB_WRITE_FLAG_RETAIN_GUID)) ?
+                                       "explicit" : "generate new");
 
        /* Internally, this is always called with a valid part number and total
         * parts.  */
@@ -2713,7 +2717,7 @@ write_wim_part(WIMStruct *wim,
        /* Use GUID if specified; otherwise generate a new one.  */
        if (guid)
                memcpy(wim->hdr.guid, guid, WIMLIB_GUID_LEN);
-       else if (!wim->guid_set_explicitly)
+       else if (!(write_flags & WIMLIB_WRITE_FLAG_RETAIN_GUID))
                randomize_byte_array(wim->hdr.guid, WIMLIB_GUID_LEN);
 
        /* Clear references to resources that have not been written yet.  */
@@ -3122,7 +3126,9 @@ overwrite_wim_via_tmpfile(WIMStruct *wim, int write_flags,
        tmpfile[wim_name_len + 9] = T('\0');
 
        ret = wimlib_write(wim, tmpfile, WIMLIB_ALL_IMAGES,
-                          write_flags | WIMLIB_WRITE_FLAG_FSYNC,
+                          write_flags |
+                               WIMLIB_WRITE_FLAG_FSYNC |
+                               WIMLIB_WRITE_FLAG_RETAIN_GUID,
                           num_threads, progress_func);
        if (ret) {
                tunlink(tmpfile);