let safe_remove fname = if Sys.file_exists fname then Sys.remove fname
+let is_dir_empty d =
+ try
+ let od = Unix.opendir d in
+ try
+ ignore (Unix.readdir od);
+ ignore (Unix.readdir od);
+ ignore (Unix.readdir od);
+ Unix.closedir od;
+ false
+ with End_of_file ->
+ Unix.closedir od;
+ true
+ with Unix.Unix_error _ -> true
+
+let safe_rmdir d = try Unix.rmdir d with Unix.Unix_error _ -> ()
+
+let rec rmdir_descend d =
+ if is_dir_empty d then
+ begin
+ safe_rmdir d;
+ rmdir_descend (Filename.dirname d)
+ end
let absolute_path file =
if file.[0] = '/' then file else Unix.getcwd () ^ "/" ^ file
let baseuri = baseuri_of_file f in
obj_file_of_baseuri baseuri
-let rec list_uniq = function
- | [] -> []
- | h::[] -> [h]
- | h1::h2::tl when h1 = h2 -> list_uniq (h2 :: tl)
- | h1::tl (* when h1 <> h2 *) -> h1 :: list_uniq tl
-
let list_tl_at ?(equality=(==)) e l =
let rec aux =
function