write.c: Move and fix check for defaulting to solid compression
authorEric Biggers <ebiggers3@gmail.com>
Sun, 17 May 2015 21:47:47 +0000 (16:47 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 17 May 2015 21:52:33 +0000 (16:52 -0500)
This check should be made higher up, not in write_file_data_blobs().

In addition, it must be checked that WIMLIB_WRITE_FLAG_PIPABLE is not set.

src/write.c

index 879a310..d0ede8b 100644 (file)
@@ -1689,16 +1689,6 @@ write_file_data_blobs(WIMStruct *wim,
 
        write_resource_flags = write_flags_to_resource_flags(write_flags);
 
-       /* wimlib v1.7.0: create a solid WIM file by default if the WIM version
-        * has been set to WIM_VERSION_SOLID and at least one blob in the WIM's
-        * blob table is located in a solid resource (may be the same WIM, or a
-        * different one in the case of export).  */
-       if (wim->out_hdr.wim_version == WIM_VERSION_SOLID &&
-           wim_has_solid_resources(wim))
-       {
-               write_resource_flags |= WRITE_RESOURCE_FLAG_SOLID;
-       }
-
        if (write_resource_flags & WRITE_RESOURCE_FLAG_SOLID) {
                out_chunk_size = wim->out_solid_chunk_size;
                out_ctype = wim->out_solid_compression_type;
@@ -2625,6 +2615,15 @@ write_pipable_wim(WIMStruct *wim, int image, int write_flags,
         * finish_write().  */
 }
 
+static bool
+should_default_to_solid_compression(WIMStruct *wim, int write_flags)
+{
+       return wim->out_hdr.wim_version == WIM_VERSION_SOLID &&
+               !(write_flags & (WIMLIB_WRITE_FLAG_SOLID |
+                                WIMLIB_WRITE_FLAG_PIPABLE)) &&
+               wim_has_solid_resources(wim);
+}
+
 /* Write a standalone WIM or split WIM (SWM) part to a new file or to a file
  * descriptor.  */
 int
@@ -2712,6 +2711,12 @@ write_wim_part(WIMStruct *wim,
        else
                wim->out_hdr.wim_version = WIM_VERSION_DEFAULT;
 
+       /* Default to solid compression if it is valid in the chosen WIM file
+        * format and the WIMStruct references any solid resources.  This is
+        * useful when exporting an image from a solid WIM.  */
+       if (should_default_to_solid_compression(wim, write_flags))
+               write_flags |= WIMLIB_WRITE_FLAG_SOLID;
+
        /* Set the header flags.  */
        wim->out_hdr.flags = (wim->hdr.flags & (WIM_HDR_FLAG_RP_FIX |
                                                WIM_HDR_FLAG_READONLY));
@@ -2989,6 +2994,12 @@ overwrite_wim_inplace(WIMStruct *wim, int write_flags, unsigned num_threads)
        if (write_flags & WIMLIB_WRITE_FLAG_SOLID)
                wim->out_hdr.wim_version = WIM_VERSION_SOLID;
 
+       /* Default to solid compression if it is valid in the chosen WIM file
+        * format and the WIMStruct references any solid resources.  This is
+        * useful when updating a solid WIM.  */
+       if (should_default_to_solid_compression(wim, write_flags))
+               write_flags |= WIMLIB_WRITE_FLAG_SOLID;
+
        /* Set additional flags for overwrite.  */
        write_flags |= WIMLIB_WRITE_FLAG_OVERWRITE |
                       WIMLIB_WRITE_FLAG_STREAMS_OK;