From f76a77b6b66a953e6b360ddf92b175754f45cfaf Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Wed, 11 Jan 2017 03:20:56 -0800 Subject: [PATCH] [driver] handle removal of symlinks in infer-out Summary: This would fail before and works as expected now: ``` $ infer -- clang -c hello.c $ cd infer-out/ && ln -s ../foo && cd .. $ infer -- clang -c hello.c # crashes because it fails to delete infer-out/foo ``` Reviewed By: jberdine Differential Revision: D4398763 fbshipit-source-id: 38465f8 --- infer/src/backend/infer.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index 158cda109..88a8f0b08 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -18,8 +18,9 @@ module F = Format let rec rmtree name = - match Unix.opendir name with - | dir -> ( + match Unix.((lstat name).st_kind) with + | S_DIR -> + let dir = Unix.opendir name in let rec rmdir dir = match Unix.readdir dir with | entry -> @@ -31,8 +32,7 @@ let rec rmtree name = Unix.closedir dir ; Unix.rmdir name in rmdir dir - ) - | exception Unix.Unix_error (Unix.ENOTDIR, _, _) -> + | _ -> Unix.unlink name | exception Unix.Unix_error (Unix.ENOENT, _, _) -> ()