mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
builder, v2v: Use imperative list functions to simplify curl arg code.
No functional change in this commit.
This commit is contained in:
@@ -95,17 +95,17 @@ and download_to t ?(progress_bar = false) ~proxy uri filename =
|
||||
|
||||
(* Get the status code first to ensure the file exists. *)
|
||||
let curl_h =
|
||||
let curl_args =
|
||||
common_args @
|
||||
(if verbose () then [] else quiet_args) @ [
|
||||
"output", Some "/dev/null"; (* Write output to /dev/null. *)
|
||||
"head", None; (* Request only HEAD. *)
|
||||
(* Write HTTP status code to stdout. *)
|
||||
"write-out", Some "%{http_code}";
|
||||
"url", Some uri
|
||||
] in
|
||||
let curl_args = ref common_args in
|
||||
if not (verbose ()) then append curl_args quiet_args;
|
||||
append curl_args [
|
||||
"output", Some "/dev/null"; (* Write output to /dev/null. *)
|
||||
"head", None; (* Request only HEAD. *)
|
||||
(* Write HTTP status code to stdout. *)
|
||||
"write-out", Some "%{http_code}";
|
||||
"url", Some uri
|
||||
];
|
||||
|
||||
Curl.create ~curl:t.curl curl_args in
|
||||
Curl.create ~curl:t.curl !curl_args in
|
||||
|
||||
let lines = Curl.run curl_h in
|
||||
if List.length lines < 1 then
|
||||
@@ -122,19 +122,18 @@ and download_to t ?(progress_bar = false) ~proxy uri filename =
|
||||
|
||||
(* Now download the file. *)
|
||||
let curl_h =
|
||||
let curl_args =
|
||||
common_args @ [
|
||||
"output", Some filename_new;
|
||||
"url", Some uri
|
||||
] in
|
||||
let curl_args = ref common_args in
|
||||
append curl_args [
|
||||
"output", Some filename_new;
|
||||
"url", Some uri
|
||||
];
|
||||
|
||||
let curl_args =
|
||||
curl_args @
|
||||
if verbose () then []
|
||||
else if progress_bar then [ "progress-bar", None ]
|
||||
else quiet_args in
|
||||
if not (verbose ()) then (
|
||||
if progress_bar then push curl_args ("progress-bar", None)
|
||||
else append curl_args quiet_args
|
||||
);
|
||||
|
||||
Curl.create ~curl:t.curl curl_args in
|
||||
Curl.create ~curl:t.curl !curl_args in
|
||||
|
||||
ignore (Curl.run curl_h)
|
||||
);
|
||||
|
||||
@@ -198,22 +198,18 @@ read the man page virt-v2v-copy-to-local(1).
|
||||
error (f_"ssh copy command failed, see earlier errors");
|
||||
|
||||
| ESXi _ ->
|
||||
let curl_args = [
|
||||
"url", Some remote_disk;
|
||||
"output", Some local_disk;
|
||||
] in
|
||||
let curl_args =
|
||||
if sslverify then curl_args
|
||||
else ("insecure", None) :: curl_args in
|
||||
let curl_args =
|
||||
match cookie with
|
||||
| None -> curl_args
|
||||
| Some cookie -> ("cookie", Some cookie) :: curl_args in
|
||||
let curl_args =
|
||||
if quiet () then ("silent", None) :: curl_args
|
||||
else curl_args in
|
||||
let curl_args = ref [
|
||||
"url", Some remote_disk;
|
||||
"output", Some local_disk;
|
||||
] in
|
||||
if not sslverify then push curl_args ("insecure", None);
|
||||
(match cookie with
|
||||
| None -> ()
|
||||
| Some cookie -> push curl_args ("cookie", Some cookie)
|
||||
);
|
||||
if quiet () then push curl_args ("silent", None);
|
||||
|
||||
let curl_h = Curl.create curl_args in
|
||||
let curl_h = Curl.create !curl_args in
|
||||
if verbose () then
|
||||
Curl.print stderr curl_h;
|
||||
ignore (Curl.run curl_h)
|
||||
|
||||
@@ -45,25 +45,23 @@ let get_session_cookie password scheme uri sslverify url =
|
||||
if !session_cookie <> "" then
|
||||
Some !session_cookie
|
||||
else (
|
||||
let curl_args = [
|
||||
"head", None;
|
||||
"silent", None;
|
||||
"url", Some url;
|
||||
] in
|
||||
let curl_args =
|
||||
match uri.uri_user, password with
|
||||
| None, None -> curl_args
|
||||
| None, Some _ ->
|
||||
warning (f_"--password-file parameter ignored because 'user@' was not given in the URL");
|
||||
curl_args
|
||||
| Some user, None ->
|
||||
("user", Some user) :: curl_args
|
||||
| Some user, Some password ->
|
||||
("user", Some (user ^ ":" ^ password)) :: curl_args in
|
||||
let curl_args =
|
||||
if not sslverify then ("insecure", None) :: curl_args else curl_args in
|
||||
let curl_args = ref [
|
||||
"head", None;
|
||||
"silent", None;
|
||||
"url", Some url;
|
||||
] in
|
||||
(match uri.uri_user, password with
|
||||
| None, None -> ()
|
||||
| None, Some _ ->
|
||||
warning (f_"--password-file parameter ignored because 'user@' was not given in the URL")
|
||||
| Some user, None ->
|
||||
push curl_args ("user", Some user)
|
||||
| Some user, Some password ->
|
||||
push curl_args ("user", Some (user ^ ":" ^ password))
|
||||
);
|
||||
if not sslverify then push curl_args ("insecure", None);
|
||||
|
||||
let curl_h = Curl.create curl_args in
|
||||
let curl_h = Curl.create !curl_args in
|
||||
let lines = Curl.run curl_h in
|
||||
|
||||
let dump_response chan =
|
||||
|
||||
Reference in New Issue
Block a user