mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
v2v: add optional tmpdir parameter for Python_script
Add an optional parameter for Python_script.create, to specific the temporary directory to use instead of creating a new one.
This commit is contained in:
@@ -31,12 +31,15 @@ type script = {
|
||||
path : string; (* Path to script. *)
|
||||
}
|
||||
|
||||
let create ?(name = "script.py") code =
|
||||
let create ?(name = "script.py") ?tmpdir code =
|
||||
let tmpdir =
|
||||
let base_dir = (open_guestfs ())#get_cachedir () in
|
||||
let t = Mkdtemp.temp_dir ~base_dir "v2v." in
|
||||
rmdir_on_exit t;
|
||||
t in
|
||||
match tmpdir with
|
||||
| None ->
|
||||
let base_dir = (open_guestfs ())#get_cachedir () in
|
||||
let t = Mkdtemp.temp_dir ~base_dir "v2v." in
|
||||
rmdir_on_exit t;
|
||||
t
|
||||
| Some dir -> dir in
|
||||
let path = tmpdir // name in
|
||||
with_open_out path (fun chan -> output_string chan code);
|
||||
{ tmpdir; path }
|
||||
|
||||
Reference in New Issue
Block a user