- /* keep track of ctype and guid just to make sure they are the same for
- * all the WIMs. */
- int ctype;
- u8 *guid;
-
- ZERO_ARRAY(swms);
- for (i = 0; i < num_swms; i++) {
- ret = wimlib_open_wim(swm_names[i],
- flags | WIMLIB_OPEN_FLAG_SPLIT_OK, &w);
- if (ret != 0)
- goto err;
-
- /* don't open all the parts at the same time, in case there are
- * a lot of them */
- fclose(w->fp);
- w->fp = NULL;
-
- if (i == 0) {
- ctype = wimlib_get_compression_type(w);
- guid = w->hdr.guid;
- } else {
- if (wimlib_get_compression_type(w) != ctype) {
- ERROR("The split WIMs do not all have the same "
- "compression type");
- ret = WIMLIB_ERR_SPLIT_INVALID;
- goto err;
- }
- if (memcmp(guid, w->hdr.guid, WIM_GID_LEN) != 0) {
- ERROR("The split WIMs do not all have the same "
- "GUID");
- ret = WIMLIB_ERR_SPLIT_INVALID;
- goto err;
- }
- }
- if (w->hdr.total_parts != num_swms) {
- ERROR("`%s' (part %d) says there are %d total parts, "
- "but %d parts were specified",
- swm_names[i], w->hdr.part_number,
- w->hdr.total_parts, num_swms);
- ret = WIMLIB_ERR_SPLIT_INVALID;
- goto err;
- }
- if (w->hdr.part_number == 0 || w->hdr.part_number > num_swms) {
- ERROR("`%s' says it is part %d, but expected a number "
- "between 1 and %d",
- swm_names[i], w->hdr.part_number, num_swms);
- ret = WIMLIB_ERR_SPLIT_INVALID;
- goto err;
- }
- part_idx = w->hdr.part_number - 1;
- if (swms[part_idx] != NULL) {
- ERROR("`%s' and `%s' both say they are part %d of %d",
- swm_names[i], swms[part_idx]->filename,
- w->hdr.part_number, num_swms);
- ret = WIMLIB_ERR_SPLIT_INVALID;
- goto err;
- }
- swms[part_idx] = w;
-
- }
- joined_wim = new_wim_struct();
- if (!joined_wim) {
- ret = WIMLIB_ERR_NOMEM;
- goto err;
- }
-
- if (flags & WIMLIB_OPEN_FLAG_CHECK_INTEGRITY)
- write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
- if (flags & WIMLIB_OPEN_FLAG_SHOW_PROGRESS)
- write_flags |= WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
-
- ret = begin_write(joined_wim, output_path, write_flags);
- if (ret != 0)
- goto err;
- ret = join_wims(swms, num_swms, joined_wim, write_flags);
-err:
- for (i = 0; i < num_swms; i++) {
- /* out_fp is the same in all the swms and joined_wim; only close
- * it one time, when freeing joined_wim. */
- if (swms[i]) {
- swms[i]->out_fp = NULL;
- wimlib_free(swms[i]);
- }
- }
- wimlib_free(joined_wim);