On Fri, Jul 15, 2022 at 08:36:19AM +0200, Laszlo Ersek wrote:
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@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.
]
This patch and your suggested enhancement are: https://github.com/libguestfs/libguestfs-common/commit/f92b8b2b65dfdb930b2da... https://github.com/libguestfs/libguestfs-common/commit/fd964c1ba94d4d72b2c1d... I made this change to guestfs-tools which is a simple renaming: https://github.com/rwmjones/guestfs-tools/commit/f5baf83e464c276d3dae6f8e878... And this is the virt-v2v commit: https://github.com/libguestfs/virt-v2v/commit/2eb6441264deb0411d36dabaf8fb2d... No change seems to be necessary for libguestfs. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html