$OpenBSD: patch-os_ml,v 1.1 2005/05/30 19:27:45 sturm Exp $
Post-release developer patch and port maintainer patch.
o Properly deal with empty directories under Windows
  (workaround for a bug in Ocaml).
  See http://lists.seas.upenn.edu/pipermail/unison-hackers/2005-May/000092.html
o Fix the failure of Windows client when a file is read-only.
  Approved by developers.
  See http://lists.seas.upenn.edu/pipermail/unison-hackers/2005-May/000087.html
--- os.ml.orig	Sat Mar 12 11:17:58 2005
+++ os.ml	Fri May 27 17:28:31 2005
@@ -150,10 +150,23 @@ and childrenOf fspath path =
         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                              *)
@@ -175,8 +188,11 @@ and delete fspath path =
              (childrenOf fspath path);
            Unix.rmdir absolutePath
        | `FILE ->
-           if Util.osType <> `Unix then
-             Unix.chmod absolutePath 0o600;
+           if Util.osType <> `Unix then begin
+             try
+               Unix.chmod absolutePath 0o600;
+             with Unix.Unix_error _ -> ()
+           end;
            Unix.unlink absolutePath;
            if Prefs.read Osx.rsrc then begin
              let pathDouble = Osx.appleDoubleFile fspath path in
