let safe_remove fname = if Sys.file_exists fname then Sys.remove fname
let is_dir_empty d =
- let od = Unix.opendir d in
- let rec aux () =
- let name = Unix.readdir od in
- if name <> "." && name <> ".." then false else aux () in
- let res = try aux () with End_of_file -> true in
- Unix.closedir od;
- res
+ try
+ let od = Unix.opendir d in
+ let rec aux () =
+ let name = Unix.readdir od in
+ if name <> "." && name <> ".." then false else aux () in
+ let res = try aux () with End_of_file -> true in
+ Unix.closedir od;
+ res
+ with
+ Unix.Unix_error _ -> true (* raised by Unix.opendir, we hope :-) *)
let safe_rmdir d = try Unix.rmdir d with Unix.Unix_error _ -> ()