From: Eric Biggers Date: Wed, 14 Aug 2013 16:15:57 +0000 (-0500) Subject: Don't require image num/name when applying from single-image pipable WIM X-Git-Tag: v1.5.0~79 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=2b04e3ff551654916caba6f6fad50908de67b0fd Don't require image num/name when applying from single-image pipable WIM --- diff --git a/doc/imagex-apply.1.in b/doc/imagex-apply.1.in index 66697f73..33c79363 100644 --- a/doc/imagex-apply.1.in +++ b/doc/imagex-apply.1.in @@ -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 - 1 dst +@IMAGEX_PROGNAME@ capture src - | @IMAGEX_PROGNAME@ apply - dst .RE .PP .SH SEE ALSO diff --git a/include/wimlib.h b/include/wimlib.h index faececa3..8c293c8a 100644 --- a/include/wimlib.h +++ b/include/wimlib.h @@ -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 diff --git a/programs/imagex.c b/programs/imagex.c index b4e3b540..8947c56d 100644 --- a/programs/imagex.c +++ b/programs/imagex.c @@ -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; diff --git a/src/extract.c b/src/extract.c index 95071bd7..092c8c40 100644 --- a/src/extract.c +++ b/src/extract.c @@ -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. */