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 66697f7..33c7936 100644 (file)
@@ -428,7 +428,7 @@ platform and filesystem-dependent, of the capture and apply functionality of
 \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
index faececa..8c293c8 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(),
- *     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
index b4e3b54..8947c56 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 (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;
index 95071bd..092c8c4 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).  */
-       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.  */