On Thursday 20 February 2014 13:08:40 Richard W.M. Jones wrote:
On Thu, Feb 20, 2014 at 11:53:16AM +0100, Pino Toscano wrote:
> Much similar to unlink_on_exit, but recursively cleaning
> directories.
> ---
>
> mllib/common_utils.ml | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
> index 3943417..f49ede6 100644
> --- a/mllib/common_utils.ml
> +++ b/mllib/common_utils.ml
> @@ -386,6 +386,35 @@ let unlink_on_exit =
>
> registered_handlers := true
>
> )
>
> +(* Remove a temporary directory on exit. *)
> +let rmdir_on_exit =
> + let dirs = ref [] in
> + let registered_handlers = ref false in
> +
> + let rec unlink_dirs () =
> + let rec recursive_rmdir fn =
> + if Sys.is_directory fn then (
I suspect this will follow symlinks, so that if the temporary
directory contains a link like:
/tmp/tmpdir/foo -> /
it will proceed to wipe out other bits of your filesystem.
Uh duh, sorry for the oversight. Fixed it checking the file type using
lstat.
Especially line 105 ff. but the rest of the function may be
interesting too in the context of patch 2/2.
Hm, it is kind of duplicating what mkdtemp already does, so I would
rather keep using it. Pity OCaml does not offer it at all...
--
Pino Toscano