- back_to_back_pack = false;
- if (!(reshdr.flags & WIM_RESHDR_FLAG_PACKED_STREAMS) ||
- cur_rspec == NULL ||
- (back_to_back_pack =
- ((reshdr.flags & WIM_RESHDR_FLAG_PACKED_STREAMS) &&
- reshdr.uncompressed_size == WIM_PACK_MAGIC_NUMBER &&
- cur_rspec != NULL &&
- cur_rspec->size_in_wim != 0)))
+ /*
+ * Possibly start a new resource.
+ *
+ * We need to start a new resource if:
+ *
+ * - There is no previous resource (cur_rspec).
+ *
+ * OR
+ *
+ * - The resource header did not have PACKED_STREAMS set, so it
+ * specifies a new, single-stream resource.
+ *
+ * OR
+ *
+ * - The resource header had PACKED_STREAMS set, and it's a
+ * special entry that specifies the resource itself as opposed
+ * to a stream, and we already encountered one such entry in
+ * the current resource. We will interpret this as the
+ * beginning of a new packed resource. (However, note that
+ * wimlib does not currently allow create WIMs with multiple
+ * packed resources, as to remain compatible with WIMGAPI.)
+ */
+ if (likely(!cur_rspec) ||
+ !(reshdr.flags & WIM_RESHDR_FLAG_PACKED_STREAMS) ||
+ (reshdr.uncompressed_size == WIM_PACK_MAGIC_NUMBER &&
+ cur_rspec->size_in_wim != 0))