Merge pull request #755 from rgrinberg/rm-rf-safety

Rm -rf safety
This commit is contained in:
Rudi Grinberg 2018-05-09 17:45:06 +07:00 committed by GitHub
commit ad4bc43a9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -489,6 +489,10 @@ let rm_rf =
Unix.rmdir dir
in
fun t ->
if not (is_local t) then (
Exn.code_error "Path.rm_rf called on external dir"
["t", sexp_of_t t]
);
let fn = to_string t in
match Unix.lstat fn with
| exception Unix.Unix_error(ENOENT, _, _) -> ()

View File

@ -158,3 +158,11 @@ Path.append (Path.of_string "/root") (Path.relative Path.build_dir "foo")
[%%expect{|
- : Stdune.Path.t = /root/_build/foo
|}]
Path.rm_rf (Path.of_string "/does/not/exist/foo/bar/baz")
[%%expect{|
Exception: Stdune__Exn.Code_error <abstr>.
Raised at file "src/stdune/exn.ml", line 30, characters 37-131
Called from file "src/stdune/path.ml", line 496, characters 4-127
Called from file "toplevel/toploop.ml", line 180, characters 17-56
|}]