Commits

camlspotter committed 45d3d40

stopping needless copy

Comments (0)

Files changed (1)

   | _ -> assert false
 
 let find_installed_cms tbl package =
-  eprintf "finding cms of %s...\n%!" (show_dest package);
+  eprintf "Finding cms of %s...\n%!" (show_dest package);
   let dest_dir = match package with 
     | Package "ocaml" -> OCaml.where 
     | Package package -> OCamlFind.dest_dir package 
     | Path p -> p
   in
-  Find.find [dest_dir] &~ fun path -> 
+  Find.find [dest_dir] &~ (fun path -> 
     if path#base = "site-lib" && package = Package "ocaml" then 
       Find.prune ()
     else match Filename.split_extension path#base with
     | body, (".cmx" | ".cmo" | ".cmi" as ext) -> 
         if verbose then Printf.eprintf "found %s\n" path#path;
         Hashtbl.add tbl (body, ext) (package, path#path)
-    | _ -> ()
+    | _ -> ());
+  !!% "Found %d entries@." & Hashtbl.length tbl
 
 let dests = 
   match dests with
             | `Same ->
                 (* The file is installed! If there is .spot/.spit, copy it! *)
                 let dirname = Filename.dirname p in
-                match 
-                  command ["cp"; spotspit; dirname] ~f:(function
-                    | (`Err, `Read mes) -> eprintf "Failed to copy %s to %s: %s\n%!" spotspit dirname mes
-                    | _ -> ())
-                with
-                | `Exited 0 -> 
-                    Hashset.add copied p;
-                    eprintf "Copied %s to %s\n%!" spotspit dirname
-                | `Exited n -> 
-                    eprintf "cp returned with a strange status %d\n%!" n
-                | _ -> eprintf "Failed to copy %s to %s: SOME STRANGE READON\n%!" spotspit dirname))
+                let destfile = dirname ^/ Filename.basename spotspit in 
+                let need_to_copy = 
+                  Sys.file_exists destfile && cmp spotspit destfile <> `Same
+                in
+                if not need_to_copy then 
+                  Hashset.add copied p                
+                else begin
+                  match 
+                    command ["/bin/cp"; spotspit; dirname] ~f:(function
+                      | (`Err, `Read mes) -> eprintf "Failed to copy %s to %s: %s\n%!" spotspit dirname mes
+                      | _ -> ())
+                  with
+                  | `Exited 0 -> 
+                      Hashset.add copied p;
+                      eprintf "Copied %s to %s\n%!" spotspit dirname
+                  | `Exited n -> 
+                      eprintf "cp returned with a strange status %d\n%!" n
+                  | _ -> eprintf "Failed to copy %s to %s: SOME STRANGE READON\n%!" spotspit dirname
+                end 
+          ))
     | _ -> ());
 
   (* check not found *)