From 9b8c6cb907d3516014450317304e4ef92853b04a Mon Sep 17 00:00:00 2001 From: EduardoRFS Date: Thu, 10 Mar 2022 14:38:37 -0300 Subject: [PATCH] fix Fpath.rm_rf error message Signed-off-by: EduardoRFS --- CHANGES.md | 2 ++ otherlibs/stdune/fpath.ml | 4 +--- otherlibs/stdune/fpath.mli | 2 +- otherlibs/stdune/path.ml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4d225d4dc90..12bfbf67d7d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,8 @@ - Show auto-detected concurrency on Windows too (#5502, @MisterDA) +- Fix operations that remove folders with absolute path. This happens when using esy (#5507, @EduardoRFS) + 3.0.3 (Unreleased) ------------------ diff --git a/otherlibs/stdune/fpath.ml b/otherlibs/stdune/fpath.ml index c5241cfef52..1e40eaef6d2 100644 --- a/otherlibs/stdune/fpath.ml +++ b/otherlibs/stdune/fpath.ml @@ -116,9 +116,7 @@ and rm_rf_dir path = deleted the directory. *) ()) -let rm_rf ?(allow_external = false) fn = - if (not allow_external) && not (Filename.is_relative fn) then - Code_error.raise "Path.rm_rf called on external dir" [ ("fn", String fn) ]; +let rm_rf fn = match Unix.lstat fn with | exception Unix.Unix_error (ENOENT, _, _) -> () | { Unix.st_kind = S_DIR; _ } -> rm_rf_dir fn diff --git a/otherlibs/stdune/fpath.mli b/otherlibs/stdune/fpath.mli index d182228cec6..26fcebe6304 100644 --- a/otherlibs/stdune/fpath.mli +++ b/otherlibs/stdune/fpath.mli @@ -34,6 +34,6 @@ type clear_dir_result = val clear_dir : string -> clear_dir_result (** If the path does not exist, this function is a no-op. *) -val rm_rf : ?allow_external:bool -> string -> unit +val rm_rf : string -> unit val is_root : string -> bool diff --git a/otherlibs/stdune/path.ml b/otherlibs/stdune/path.ml index 2867394574e..27d219dac4b 100644 --- a/otherlibs/stdune/path.ml +++ b/otherlibs/stdune/path.ml @@ -1049,7 +1049,7 @@ let clear_dir dir = Fpath.clear_dir (to_string dir) let rm_rf ?(allow_external = false) t = if (not allow_external) && not (is_managed t) then Code_error.raise "Path.rm_rf called on external dir" [ ("t", to_dyn t) ]; - Fpath.rm_rf ~allow_external (to_string t) + Fpath.rm_rf (to_string t) let mkdir_p ?perms = function | External s -> External.mkdir_p s ?perms