mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
builder: Pass ~prog global (program name) around.
This commit is contained in:
@@ -138,7 +138,7 @@ let main () =
|
||||
fun (source, fingerprint) ->
|
||||
let sigchecker =
|
||||
Sigchecker.create ~debug ~gpg ~fingerprint ~check_signature in
|
||||
Index_parser.get_index ~debug ~downloader ~sigchecker source
|
||||
Index_parser.get_index ~prog ~debug ~downloader ~sigchecker source
|
||||
) sources
|
||||
) in
|
||||
|
||||
@@ -178,7 +178,7 @@ let main () =
|
||||
let template = name, revision in
|
||||
msg (f_"Downloading: %s") file_uri;
|
||||
let progress_bar = not quiet in
|
||||
ignore (Downloader.download downloader ~template ~progress_bar
|
||||
ignore (Downloader.download ~prog downloader ~template ~progress_bar
|
||||
file_uri)
|
||||
) index;
|
||||
exit 0
|
||||
@@ -218,7 +218,7 @@ let main () =
|
||||
let template = arg, revision in
|
||||
msg (f_"Downloading: %s") file_uri;
|
||||
let progress_bar = not quiet in
|
||||
Downloader.download downloader ~template ~progress_bar file_uri in
|
||||
Downloader.download ~prog downloader ~template ~progress_bar file_uri in
|
||||
if delete_on_exit then unlink_on_exit template;
|
||||
template in
|
||||
|
||||
@@ -236,7 +236,7 @@ let main () =
|
||||
| { Index_parser.signature_uri = None } -> None
|
||||
| { Index_parser.signature_uri = Some signature_uri } ->
|
||||
let sigfile, delete_on_exit =
|
||||
Downloader.download downloader signature_uri in
|
||||
Downloader.download ~prog downloader signature_uri in
|
||||
if delete_on_exit then unlink_on_exit sigfile;
|
||||
Some sigfile in
|
||||
|
||||
|
||||
@@ -43,19 +43,19 @@ let create ~debug ~curl ~cache = {
|
||||
cache = cache;
|
||||
}
|
||||
|
||||
let rec download t ?template ?progress_bar uri =
|
||||
let rec download ~prog t ?template ?progress_bar uri =
|
||||
match template with
|
||||
| None -> (* no cache, simple download *)
|
||||
(* Create a temporary name. *)
|
||||
let tmpfile = Filename.temp_file "vbcache" ".txt" in
|
||||
download_to t ?progress_bar uri tmpfile;
|
||||
download_to ~prog t ?progress_bar uri tmpfile;
|
||||
(tmpfile, true)
|
||||
|
||||
| Some (name, revision) ->
|
||||
match t.cache with
|
||||
| None ->
|
||||
(* Not using the cache at all? *)
|
||||
download t ?progress_bar uri
|
||||
download t ~prog ?progress_bar uri
|
||||
|
||||
| Some cachedir ->
|
||||
let filename = cache_of_name cachedir name revision in
|
||||
@@ -64,11 +64,11 @@ let rec download t ?template ?progress_bar uri =
|
||||
* If not, download it.
|
||||
*)
|
||||
if not (Sys.file_exists filename) then
|
||||
download_to t ?progress_bar uri filename;
|
||||
download_to ~prog t ?progress_bar uri filename;
|
||||
|
||||
(filename, false)
|
||||
|
||||
and download_to t ?(progress_bar = false) uri filename =
|
||||
and download_to ~prog t ?(progress_bar = false) uri filename =
|
||||
(* Get the status code first to ensure the file exists. *)
|
||||
let cmd = sprintf "%s%s -g -o /dev/null -I -w '%%{http_code}' %s"
|
||||
t.curl
|
||||
@@ -99,8 +99,8 @@ and download_to t ?(progress_bar = false) uri filename =
|
||||
| _ -> false
|
||||
in
|
||||
if bad_status_code status_code then (
|
||||
eprintf (f_"virt-builder: failed to download %s: HTTP status code %s\n")
|
||||
uri status_code;
|
||||
eprintf (f_"%s: failed to download %s: HTTP status code %s\n")
|
||||
prog uri status_code;
|
||||
exit 1
|
||||
);
|
||||
|
||||
@@ -120,7 +120,8 @@ and download_to t ?(progress_bar = false) uri filename =
|
||||
if t.debug then eprintf "%s\n%!" cmd;
|
||||
let r = Sys.command cmd in
|
||||
if r <> 0 then (
|
||||
eprintf (f_"virt-builder: curl (download) command failed downloading '%s'\n") uri;
|
||||
eprintf (f_"%s: curl (download) command failed downloading '%s'\n")
|
||||
prog uri;
|
||||
exit 1
|
||||
);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ type t
|
||||
val create : debug:bool -> curl:string -> cache:string option -> t
|
||||
(** Create the abstract type. *)
|
||||
|
||||
val download : t -> ?template:(string*int) -> ?progress_bar:bool -> uri -> (filename * bool)
|
||||
val download : prog:string -> t -> ?template:(string*int) -> ?progress_bar:bool -> uri -> (filename * bool)
|
||||
(** Download the URI, returning the downloaded filename and a
|
||||
temporary file flag. The temporary file flag is [true] iff
|
||||
the downloaded file is temporary and should be deleted by the
|
||||
|
||||
@@ -106,7 +106,7 @@ and field = string * string (* key + value *)
|
||||
(* Calls yyparse in the C code. *)
|
||||
external parse_index : string -> sections = "virt_builder_parse_index"
|
||||
|
||||
let get_index ~debug ~downloader ~sigchecker source =
|
||||
let get_index ~prog ~debug ~downloader ~sigchecker source =
|
||||
let corrupt_file () =
|
||||
eprintf (f_"\nThe index file downloaded from '%s' is corrupt.\nYou need to ask the supplier of this file to fix it and upload a fixed version.\n")
|
||||
source;
|
||||
@@ -115,7 +115,7 @@ let get_index ~debug ~downloader ~sigchecker source =
|
||||
|
||||
let rec get_index () =
|
||||
(* Get the index page. *)
|
||||
let tmpfile, delete_tmpfile = Downloader.download downloader source in
|
||||
let tmpfile, delete_tmpfile = Downloader.download ~prog downloader source in
|
||||
|
||||
(* Check index file signature (also verifies it was fully
|
||||
* downloaded and not corrupted in transit).
|
||||
|
||||
@@ -35,4 +35,4 @@ and entry = {
|
||||
sigchecker : Sigchecker.t;
|
||||
}
|
||||
|
||||
val get_index : debug:bool -> downloader:Downloader.t -> sigchecker:Sigchecker.t -> string -> index
|
||||
val get_index : prog:string -> debug:bool -> downloader:Downloader.t -> sigchecker:Sigchecker.t -> string -> index
|
||||
|
||||
Reference in New Issue
Block a user