]> wimlib.net Git - wimlib/commitdiff
Don't require image num/name when applying from single-image pipable WIM
authorEric Biggers <ebiggers3@gmail.com>
Wed, 14 Aug 2013 16:15:57 +0000 (11:15 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Wed, 14 Aug 2013 16:17:03 +0000 (11:17 -0500)
doc/imagex-apply.1.in
include/wimlib.h
programs/imagex.c
src/extract.c

index 66697f732909191ca24319f33187269658eef613..33c793635948bdb8dca37c0f951ff8ffa4164f81 100644 (file)
@@ -428,7 +428,7 @@ platform and filesystem-dependent, of the capture and apply functionality of
 \fB@IMAGEX_PROGNAME@\fR):
 .RS
 .PP
 \fB@IMAGEX_PROGNAME@\fR):
 .RS
 .PP
-@IMAGEX_PROGNAME@ capture src - | @IMAGEX_PROGNAME@ apply - dst
+@IMAGEX_PROGNAME@ capture src - | @IMAGEX_PROGNAME@ apply - dst
 .RE
 .PP
 .SH SEE ALSO
 .RE
 .PP
 .SH SEE ALSO
index faececa310df642f92c3514ba32937dd235f9235..8c293c8a81d42dbbd867f0b5e6b3878959843737 100644 (file)
@@ -1890,7 +1890,9 @@ wimlib_extract_image(WIMStruct *wim, int image,
  *     String that specifies the 1-based index or name of the image to extract.
  *     It is translated to an image index using the same rules that
  *     wimlib_resolve_image() uses.  However, unlike wimlib_extract_image(),
  *     String that specifies the 1-based index or name of the image to extract.
  *     It is translated to an image index using the same rules that
  *     wimlib_resolve_image() uses.  However, unlike wimlib_extract_image(),
- *     only a single image (not all images) can be specified.
+ *     only a single image (not all images) can be specified.  Alternatively,
+ *     specify @p NULL here to use the first image in the WIM if it contains
+ *     exactly one image but otherwise return @p WIMLIB_ERR_INVALID_IMAGE.
  * @param target
  *     Same as the corresponding parameter to wimlib_extract_image().
  * @param extract_flags
  * @param target
  *     Same as the corresponding parameter to wimlib_extract_image().
  * @param extract_flags
index b4e3b540d391ff30d67d16f21aa567dc843bcae4..8947c56dfb1674857c9728d4a585c93beffabe36 100644 (file)
@@ -1514,14 +1514,13 @@ imagex_apply(int argc, tchar **argv, int cmd)
 
        if (!tstrcmp(wimfile, T("-"))) {
                /* Attempt to apply pipable WIM from standard input.  */
 
        if (!tstrcmp(wimfile, T("-"))) {
                /* Attempt to apply pipable WIM from standard input.  */
-               if (argc < 3) {
-                       imagex_error(T("Imagex index or name must be explicitly "
-                                      "specified when applying pipable WIM on "
-                                      "standard input."));
-                       goto out_usage;
+               if (argc == 2) {
+                       image_num_or_name = NULL;
+                       target = argv[1];
+               } else {
+                       image_num_or_name = argv[1];
+                       target = argv[2];
                }
                }
-               image_num_or_name = argv[1];
-               target = argv[2];
                wim = NULL;
                num_additional_swms = 0;
                additional_swms = NULL;
                wim = NULL;
                num_additional_swms = 0;
                additional_swms = NULL;
index 95071bd7bfbb35b45dec106755a88b1c0db204e8..092c8c4033a26659ee270ddf406d5d63d328bd1a 100644 (file)
@@ -2629,16 +2629,26 @@ wimlib_extract_image_from_pipe(int pipe_fd, const tchar *image_num_or_name,
 
        /* Get image index (this may use the XML data that was just read to
         * resolve an image name).  */
 
        /* Get image index (this may use the XML data that was just read to
         * resolve an image name).  */
-       image = wimlib_resolve_image(pwm, image_num_or_name);
-       if (image == WIMLIB_NO_IMAGE) {
-               ERROR("\"%"TS"\" is not a valid image in the pipable WIM!",
-                     image_num_or_name);
-               ret = WIMLIB_ERR_INVALID_IMAGE;
-               goto out_wimlib_free;
-       } else if (image == WIMLIB_ALL_IMAGES) {
-               ERROR("Applying all images from a pipe is not supported.");
-               ret = WIMLIB_ERR_INVALID_IMAGE;
-               goto out_wimlib_free;
+       if (image_num_or_name) {
+               image = wimlib_resolve_image(pwm, image_num_or_name);
+               if (image == WIMLIB_NO_IMAGE) {
+                       ERROR("\"%"TS"\" is not a valid image in the pipable WIM!",
+                             image_num_or_name);
+                       ret = WIMLIB_ERR_INVALID_IMAGE;
+                       goto out_wimlib_free;
+               } else if (image == WIMLIB_ALL_IMAGES) {
+                       ERROR("Applying all images from a pipe is not supported.");
+                       ret = WIMLIB_ERR_INVALID_IMAGE;
+                       goto out_wimlib_free;
+               }
+       } else {
+               if (pwm->hdr.image_count != 1) {
+                       ERROR("No image was specified, but the pipable WIM "
+                             "did not contain exactly 1 image");
+                       ret = WIMLIB_ERR_INVALID_IMAGE;
+                       goto out_wimlib_free;
+               }
+               image = 1;
        }
 
        /* Load the needed metadata resource.  */
        }
 
        /* Load the needed metadata resource.  */