[Libguestfs] [PATCH v2 1/2] mllib: curl: add optional tmpdir parameter

Pino Toscano ptoscano at redhat.com
Tue Oct 25 08:24:40 UTC 2016


Add a new optional parameter for the Curl ADT, so temporary files can be
created in a specified directory (which is supposed to be temporary, and
disposed only when the application quits).
---
 mllib/curl.ml  | 10 ++++++----
 mllib/curl.mli |  2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/mllib/curl.ml b/mllib/curl.ml
index 376406e..baa75ec 100644
--- a/mllib/curl.ml
+++ b/mllib/curl.ml
@@ -25,6 +25,7 @@ let quote = Filename.quote
 type t = {
   curl : string;
   args : args;
+  tmpdir : string option;
 }
 and args = (string * string option) list
 
@@ -40,12 +41,13 @@ let args_of_proxy = function
   | SystemProxy ->     []
   | ForcedProxy url -> [ "proxy", Some url; "noproxy", Some "" ]
 
-let create ?(curl = "curl") ?(proxy = SystemProxy) args =
+let create ?(curl = "curl") ?(proxy = SystemProxy) ?tmpdir args =
   let args = safe_args @ args_of_proxy proxy @ args in
-  { curl = curl; args = args }
+  { curl = curl; args = args; tmpdir = tmpdir }
 
-let run { curl = curl; args = args } =
-  let config_file, chan = Filename.open_temp_file "guestfscurl" ".conf" in
+let run { curl = curl; args = args; tmpdir = tmpdir } =
+  let config_file, chan = Filename.open_temp_file ?temp_dir:tmpdir
+    "guestfscurl" ".conf" in
   List.iter (
     function
     | name, None -> fprintf chan "%s\n" name
diff --git a/mllib/curl.mli b/mllib/curl.mli
index f045572..c0c2fb0 100644
--- a/mllib/curl.mli
+++ b/mllib/curl.mli
@@ -27,7 +27,7 @@ type proxy =
   | SystemProxy           (** Use the system settings. *)
   | ForcedProxy of string (** The proxy is forced to the specified URL. *)
 
-val create : ?curl:string -> ?proxy:proxy -> args -> t
+val create : ?curl:string -> ?proxy:proxy -> ?tmpdir:string -> args -> t
 (** Create a curl command handle.
 
     The curl arguments are a list of key, value pairs corresponding
-- 
2.7.4




More information about the Libguestfs mailing list