From 3e802605b52dccd2574353d5aff220de8d8eb3b8 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 7 Jan 2014 17:30:20 +0000 Subject: [PATCH] builder: Pass ~prog global (program name) around. --- builder/builder.ml | 8 ++++---- builder/downloader.ml | 17 +++++++++-------- builder/downloader.mli | 2 +- builder/index_parser.ml | 4 ++-- builder/index_parser.mli | 2 +- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/builder/builder.ml b/builder/builder.ml index 84d575730..aca4ac9d4 100644 --- a/builder/builder.ml +++ b/builder/builder.ml @@ -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 diff --git a/builder/downloader.ml b/builder/downloader.ml index 918227e01..442a01106 100644 --- a/builder/downloader.ml +++ b/builder/downloader.ml @@ -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 ); diff --git a/builder/downloader.mli b/builder/downloader.mli index 8cb740430..62d500db9 100644 --- a/builder/downloader.mli +++ b/builder/downloader.mli @@ -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 diff --git a/builder/index_parser.ml b/builder/index_parser.ml index fb47e50b7..453a3a185 100644 --- a/builder/index_parser.ml +++ b/builder/index_parser.ml @@ -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). diff --git a/builder/index_parser.mli b/builder/index_parser.mli index 0b6317dce..54f18074a 100644 --- a/builder/index_parser.mli +++ b/builder/index_parser.mli @@ -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