[Libguestfs] [PATCH] v2v: disk: strip only common extension (RHBZ#1365005)

Richard W.M. Jones rjones at redhat.com
Mon Aug 8 15:02:42 UTC 2016


On Mon, Aug 08, 2016 at 03:51:55PM +0200, Pino Toscano wrote:
> In disk input mode, to determine the guest name strip the extension from
> the filename only if it's a very well extension for disk images.
> ---
>  v2v/input_disk.ml | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)

ACK, although ...

> diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml
> index 17ad61d..939a16b 100644
> --- a/v2v/input_disk.ml
> +++ b/v2v/input_disk.ml
> @@ -42,9 +42,13 @@ class input_disk input_format disk = object
>       * the filename passed in.  Users can override this using the
>       * `-on name' option.
>       *)
> -    let name = Filename.basename disk in
>      let name =
> -      try Filename.chop_extension name with Invalid_argument _ -> name in
> +      let name = Filename.basename disk in
> +      let ext = last_part_of name '.' in
> +      (* Remove the extension, only if it's one usually used for disk images. *)
> +      match ext with
> +      | Some ("img"|"qcow2"|"raw"|"vmdk") -> Filename.chop_extension name

... you might consider chopping "-sda" (you'll need a different
code path, because there is no dot).

However don't worry if it's too much trouble.

Rich.

> +      | None | Some _ -> name in
>      if name = "" then
>        error (f_"-i disk: invalid input filename (%s)") disk;
>  
> -- 
> 2.7.4
> 
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW




More information about the Libguestfs mailing list