[Unison-hackers] Patches common to 2.10.2 and 2.12.0

Jerome Vouillon Jerome.Vouillon at pps.jussieu.fr
Fri May 27 17:46:45 EDT 2005


These patches apply to both Unison 2.10.2 and 2.12.0.

-- Jerome
-------------- next part --------------
Better error message for non-existing paths
Index: src/update.ml
===================================================================
--- src/update.ml       (revision 28)
+++ src/update.ml       (revision 29)
@@ -1594,7 +1594,6 @@
 let rec buildUpdate archive fspath fullpath here path =
   match Path.deconstruct path with
     None ->
-      Os.checkThatParentPathIsADir fspath here;
       showStatus path;
       let (arch, ui) =
         buildUpdateRec archive fspath here (useFastChecking()) in
@@ -1604,6 +1603,12 @@
        end,
        ui)
   | Some(name, path') ->
+      if not (isDir fspath here) then
+        (archive,
+         Error (Printf.sprintf
+                  "path %s is not valid because %s is not a directory"
+                  (Path.toString fullpath) (Path.toString here)))
+      else
       let children = getChildren fspath here in
       let (name', status) =
         try
-------------- next part --------------
Properly deal with empty directories under Windows (workaround for a
bug in Ocaml)
Index: src/os.ml
===================================================================
--- src/os.ml   (revision 28)
+++ src/os.ml   (revision 29)
@@ -150,10 +150,23 @@
         loop newChildren directory
       in
       let absolutePath = Fspath.concat fspath path in
-      let directory = Fspath.opendir absolutePath in
-      let result = loop [] directory in
-      Unix.closedir directory;
-      result)
+      let directory =
+        try
+          Some (Fspath.opendir absolutePath)
+        with Unix.Unix_error (Unix.ENOENT, _, _) ->
+          (* FIX (in Ocaml): under Windows, when a directory is empty
+             (not even "." and ".."), FindFirstFile fails with
+             ERROR_FILE_NOT_FOUND while ocaml expects the error
+             ERROR_NO_MORE_FILES *)
+          None
+      in
+      match directory with
+        Some directory ->
+          let result = loop [] directory in
+          Unix.closedir directory;
+          result
+      | None ->
+          [])
 
 (*****************************************************************************)
 (*                        ACTIONS ON FILESYSTEM                              *)
-------------- next part --------------
Correct quoting of ignored patterns generated by the UI.
Index: src/uicommon.ml
===================================================================
--- src/uicommon.ml     (revision 28)
+++ src/uicommon.ml     (revision 29)
@@ -275,26 +275,28 @@
     | c ->
         buf.[!pos] <- c; pos := !pos + 1
   done;
-  String.sub buf 0 !pos
+  "{" ^ String.sub buf 0 !pos ^ "}"
 
-let ignorePath path = "Path " ^ (quote (Path.toString path))
+let ignorePath path = "Path " ^ quote (Path.toString path)
 
 let ignoreName path =
   match Path.finalName path with
-    Some name -> "Name " ^ (quote (Name.toString name))
+    Some name -> "Name " ^ quote (Name.toString name)
   | None      -> assert false
 
 let ignoreExt path =
   match Path.finalName path with
     Some name ->
       let str = Name.toString name in
-      (try
-        let pos = String.rindex str '.' + 1 in
+      begin try
+        let pos = String.rindex str '.' in
         let ext = String.sub str pos (String.length str - pos) in
-        "Name *." ^ (quote ext)
+        "Name {,.}*" ^ quote ext
       with Not_found -> (* str does not contain '.' *)
-        "Name "^(quote str))
-  | None      -> assert false
+        "Name " ^ quote str
+      end
+  | None ->
+      assert false
 
 let addIgnorePattern theRegExp =
   if theRegExp = "Path " then
-------------- next part --------------
Catch failure of localtime library call.
--- unison-2.12.0.orig/ubase/util.ml	2005-03-12 17:17:58.000000000 +0100
+++ unison-2.12.0/ubase/util.ml	2005-05-27 16:32:39.743265166 +0200
@@ -244,14 +244,18 @@
   convertUnixErrorsToTransient "time" Unix.time
 
 let time2string timef =
-  let time = localtime timef in
-  Printf.sprintf
-    "%2d:%.2d on %2d %3s, %4d"
-    time.Unix.tm_hour
-    time.Unix.tm_min
-    time.Unix.tm_mday
-    (monthname time.Unix.tm_mon)
-    (time.Unix.tm_year + 1900)
+  try
+    let time = localtime timef in
+    Printf.sprintf
+      "%2d:%.2d:%.2d on %2d %3s, %4d"
+      time.Unix.tm_hour
+      time.Unix.tm_min
+      time.Unix.tm_sec
+      time.Unix.tm_mday
+      (monthname time.Unix.tm_mon)
+      (time.Unix.tm_year + 1900)
+  with Transient _ ->
+    "(invalid date)"
 
 let percentageOfTotal current total =
   (int_of_float ((float current) *. 100.0 /. (float total)))
-------------- next part --------------
Missing call to restoreTerminal.
Index: src/uitext.ml
===================================================================
--- src/uitext.ml       (revision 28)
+++ src/uitext.ml       (revision 29)
@@ -426,6 +426,8 @@
                  (["n";"q";"x"],
                     ("Exit"),
                     fun()->
+                      alwaysDisplay "\n";
+                      restoreTerminal ();
                       Lwt_unix.run (Update.unlockArchives ());
                       exit 1)]
                 (fun()-> display  "Press return to continue.")


More information about the Unison-hackers mailing list