Commits

UENISHI Kota  committed 7a45348

more robust on various errors

  • Participants
  • Parent commits 38dc98a

Comments (0)

Files changed (1)

File ocaml/findup.ml

   maybe_add s md5 path m2
 
 and handle_name m path =
-  if Sys.is_directory path then
-    search_dup_fold m path
+  try 
+    if Sys.is_directory path then
+      search_dup_fold m path
 
-  else
+    else
     (* TODO: calculating md5 is just heavy *)
-    let md5 = Digest.to_hex (Digest.file path) in
-    let stat = Unix.stat path in
-    let size = stat.Unix.st_size in
-    maybe_add size md5 path m
+      let md5 = Digest.to_hex (Digest.file path) in
+      let stat = Unix.stat path in
+      let size = stat.Unix.st_size in
+      maybe_add size md5 path m
+
+  with
+    Sys_error str ->
+      Printf.eprintf ">> %s\n" str;
+      (0, "", m)
 
 let search_dup path =
   Printf.printf "searching for dup files in %s\n" path;
     List.iter (fun n -> Printf.printf "%s " n.name) nodes;
     print_endline "";
     print_list nextq
-  with _ ->
-    ()
+  with LimitQ.Queue_is_empty -> ()
 
 let main () =
   let path =
   in
   let tree = search_dup path in
   (* print_tree tree; *)
+  print_endline "";
   print_list (sort_tree_by_size tree);;