From: Eric Biggers Date: Wed, 14 May 2014 18:37:57 +0000 (-0500) Subject: Add WIMLIB_WRITE_FLAG_RETAIN_GUID X-Git-Tag: v1.7.0~161 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=5f8590a7dcdf45a7f56f50ad96ac6349ffbafc08;ds=sidebyside Add WIMLIB_WRITE_FLAG_RETAIN_GUID ... and use it in wimlib_join() and wimlib_overwrite(). Remove the guid_set_explicitly hack. --- diff --git a/include/wimlib.h b/include/wimlib.h index 0684d625..52c95424 100644 --- a/include/wimlib.h +++ b/include/wimlib.h @@ -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 diff --git a/include/wimlib/wim.h b/include/wimlib/wim.h index 42d109ed..ea916aa6 100644 --- a/include/wimlib/wim.h +++ b/include/wimlib/wim.h @@ -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; diff --git a/include/wimlib/write.h b/include/wimlib/write.h index 190bf941..7e913e1a 100644 --- a/include/wimlib/write.h +++ b/include/wimlib/write.h @@ -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) diff --git a/src/join.c b/src/join.c index f61eaaf5..71e43c09 100644 --- a/src/join.c +++ b/src/join.c @@ -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++) diff --git a/src/wim.c b/src/wim.c index 2d788b07..960a9d50 100644 --- 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) { diff --git a/src/write.c b/src/write.c index e7888cd4..f34481aa 100644 --- a/src/write.c +++ b/src/write.c @@ -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);