[Libguestfs] [PATCH 3/3] builder: do a copy when downloading local files

Pino Toscano ptoscano at redhat.com
Tue Feb 11 12:09:37 UTC 2014


Instead of spawning curl even to "download" file:// URIs, just copy
them.
---
 builder/downloader.ml | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/builder/downloader.ml b/builder/downloader.ml
index 95b5817..e386c06 100644
--- a/builder/downloader.ml
+++ b/builder/downloader.ml
@@ -84,6 +84,17 @@ and download_to ~prog t ?(progress_bar = false) uri filename =
   unlink_on_exit filename_new;
 
   (match parseduri.URI.protocol with
+  | "file" ->
+    let path = parseduri.URI.path in
+    let cmd = sprintf "cp%s %s %s"
+      (if t.debug then " -v" else "")
+      (quote path) (quote filename_new) in
+    let r = Sys.command cmd in
+    if r <> 0 then (
+      eprintf (f_"%s: cp (download) command failed copying '%s'\n")
+        prog path;
+      exit 1
+    )
   | _ -> (* Any other protocol. *)
     (* Get the status code first to ensure the file exists. *)
     let cmd = sprintf "%s%s -g -o /dev/null -I -w '%%{http_code}' %s"
-- 
1.8.3.1




More information about the Libguestfs mailing list