On 1/15/24 19:24, Richard W.M. Jones wrote:
> The existing 'scp_from_remote_to_temporary' wrapper around scp was
> pretty weird (I think from much patching without refactoring).
> Simplify it so it no longer generates the output filename, and rename
> it accordingly to 'download_file' (as we will soon remove the need for
> and dependency on 'scp').
> ---
>  input/ssh.mli                  |  7 +++----
>  input/parse_domain_from_vmx.ml |  4 ++--
>  input/ssh.ml                   | 13 ++++---------
>  3 files changed, 9 insertions(+), 15 deletions(-)
> 
> diff --git a/input/ssh.mli b/input/ssh.mli
> index e9a1a6a8c7..62e78bd3e8 100644
> --- a/input/ssh.mli
> +++ b/input/ssh.mli
> @@ -27,8 +27,7 @@ val port_of_uri : Xml.uri -> int option
>      is ignored). *)
>  val remote_file_exists : Xml.uri -> string -> bool
>  
> -(** [scp_from_remote_to_temporary ssh_uri tmpdir filename]
> +(** [download_file ssh_uri output]
>      uses scp to copy the single remote file at [ssh_uri] to
> -    the local file called [tmpdir/filename].  It returns the
> -    final path [tmpdir/filename]. *)
> -val scp_from_remote_to_temporary : Xml.uri -> string -> string -> string
> +    the local file called [output]. *)
> +val download_file : Xml.uri -> string -> unit
> diff --git a/input/parse_domain_from_vmx.ml b/input/parse_domain_from_vmx.ml
> index 8cf5893c35..e6500da64a 100644
> --- a/input/parse_domain_from_vmx.ml
> +++ b/input/parse_domain_from_vmx.ml
> @@ -335,8 +335,8 @@ let parse_domain_from_vmx vmx_source =
>      match vmx_source with
>      | File filename -> Parse_vmx.parse_file filename
>      | SSH uri ->
> -       let filename = Ssh.scp_from_remote_to_temporary uri tmpdir
> -                        "source.vmx" in
> +       let filename = tmpdir // "source.vmx" in
> +       Ssh.download_file uri filename;
>         Parse_vmx.parse_file filename in
>  
>    let name =
> diff --git a/input/ssh.ml b/input/ssh.ml
> index 8e12899a8e..fbc0e54f5d 100644
> --- a/input/ssh.ml
> +++ b/input/ssh.ml
> @@ -32,12 +32,8 @@ let server_of_uri { Xml.uri_server } =
>  let path_of_uri { Xml.uri_path } =
>    match uri_path with None -> assert false | Some p -> p
>  
> -(* 'scp' a remote file into a temporary local file, returning the path
> - * of the temporary local file.
> - *)
> -let scp_from_remote_to_temporary uri tmpdir filename =
> -  let localfile = tmpdir // filename in
> -
> +(* 'scp' a remote file into a local file. *)
> +let download_file uri output =
>    let cmd =
>      sprintf "scp%s%s %s%s:%s %s"
>              (if verbose () then "" else " -q")
> @@ -49,13 +45,12 @@ let scp_from_remote_to_temporary uri tmpdir filename =
>               | Some user -> quote user ^ "@")
>              (quote (server_of_uri uri))
>              (quote (path_of_uri uri))
> -            (quote localfile) in
> +            (quote output) in
>    if verbose () then
>      eprintf "%s\n%!" cmd;
>    if Sys.command cmd <> 0 then
>      error (f_"could not copy the VMX file from the remote server, \
> -              see earlier error messages");
> -  localfile
> +              see earlier error messages")
>  
>  (* Test if [path] exists on the remote server. *)
>  let remote_file_exists uri path =

Reviewed-by: Laszlo Ersek <ler...@redhat.com>
_______________________________________________
Libguestfs mailing list -- guestfs@lists.libguestfs.org
To unsubscribe send an email to guestfs-le...@lists.libguestfs.org

Reply via email to