On Sunday, 5 November 2017 20:42:40 CET Richard W.M. Jones wrote:
These safe wrappers around Pervasives.open_in and Pervasives.open_out ensure that exceptions escaping cannot leave unclosed files. ---
Mostly LGTM, just one note/improvement.
diff --git a/v2v/input_libvirt_vddk.ml b/v2v/input_libvirt_vddk.ml index 63e76a5aa..e29fbc2b7 100644 --- a/v2v/input_libvirt_vddk.ml +++ b/v2v/input_libvirt_vddk.ml @@ -240,10 +240,11 @@ object "password=-" | Some password -> let password_file = tmpdir // "password" in - let chan = open_out password_file in - chmod password_file 0o600; - output_string chan password; - close_out chan; + with_open_out password_file ( + fun chan -> + chmod password_file 0o600; + output_string chan password + );
Now that I see this, the chmod could be directly on the fd of the open channel, to be sure to perform it on the actual file: fchmod (descr_of_out_channel chan) 0o600; Thanks, -- Pino Toscano