[Libguestfs] [PATCH common 1/4] mltools: Rename On_exit.rmdir to On_exit.rm_rf

Laszlo Ersek lersek at redhat.com
Fri Jul 15 06:36:19 UTC 2022


On 07/14/22 14:36, Richard W.M. Jones wrote:
> Make it clearer what this function does and that it's potentially
> dangerous.  The functionality itself is unchanged.
> ---
>  mltools/on_exit.ml  | 2 +-
>  mltools/on_exit.mli | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mltools/on_exit.ml b/mltools/on_exit.ml
> index 53ccb68..9cdc496 100644
> --- a/mltools/on_exit.ml
> +++ b/mltools/on_exit.ml
> @@ -102,7 +102,7 @@ let unlink filename =
>    register ();
>    List.push_front filename files
>  
> -let rmdir dir =
> +let rm_rf dir =
>    register ();
>    List.push_front dir rmdirs
>  
> diff --git a/mltools/on_exit.mli b/mltools/on_exit.mli
> index a02e3db..9bcf104 100644
> --- a/mltools/on_exit.mli
> +++ b/mltools/on_exit.mli
> @@ -47,7 +47,7 @@ val f : (unit -> unit) -> unit
>  val unlink : string -> unit
>  (** Unlink a single temporary file on exit. *)
>  
> -val rmdir : string -> unit
> +val rm_rf : string -> unit
>  (** Recursively remove a temporary directory on exit (using [rm -rf]). *)
>  
>  val kill : ?signal:int -> int -> unit
> 

Reviewed-by: Laszlo Ersek <lersek at redhat.com>

[

Potential small improvement (separate, independent patch; feel free to
push together with the rest, if you think it makes sense -- I didn't
test it though, of course):

diff --git a/mltools/on_exit.ml b/mltools/on_exit.ml
index 53ccb68ab0ce..a9e7f3201eba 100644
--- a/mltools/on_exit.ml
+++ b/mltools/on_exit.ml
@@ -52,7 +52,7 @@ let do_actions () =
     List.iter (do_action (fun file -> Unix.unlink file)) !files;
     List.iter (do_action (
       fun dir ->
-        let cmd = sprintf "rm -rf %s" (Filename.quote dir) in
+        let cmd = sprintf "rm -rf -- %s" (Filename.quote dir) in
         ignore (Tools_utils.shell_command cmd)
       )
     ) !rmdirs;

This would be to pacify my inner pedant. :) I don't expect "dir" to
start with a hyphen, but this is supposed to be a generic function.

]

Thanks!
Laszlo



More information about the Libguestfs mailing list