diff -a -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/daemon/common/commonOptions.ml ./src/daemon/common/commonOptions.ml
--- ./src/daemon/common/commonOptions.ml	2006-03-05 11:43:46.000000000 +0100
+++ ./src/daemon/common/commonOptions.ml	2006-03-06 18:55:38.000000000 +0100
@@ -1597,7 +1597,7 @@
   option_hook log_file (fun _ ->
       if !!log_file <> "" then
         try
-	  if Sys.file_exists !!log_file then
+	  if Unix32.file_exists !!log_file then
 	    if (Unix32.getsize !!log_file)
 	     > (Int64ops.megabytes !!log_file_size) then begin
 	      Sys.remove !!log_file;
diff -a -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/networks/donkey/donkeyGlobals.ml ./src/networks/donkey/donkeyGlobals.ml
--- ./src/networks/donkey/donkeyGlobals.ml	2006-02-09 12:41:39.000000000 +0100
+++ ./src/networks/donkey/donkeyGlobals.ml	2006-03-06 18:55:38.000000000 +0100
@@ -325,7 +325,6 @@
   with _ ->
       if !verbose_share then
         lprintf_nl () "New file with md4: %s" (Md4.to_string md4);
-      ignore (Unix32.file_exists file_diskname);
 
       let t =
         if
@@ -334,7 +333,7 @@
 (* Only if the option is set *)
           !!emulate_sparsefiles &&
 (* Only if the file does not already exists *)
-          not (Sys.file_exists file_diskname)
+          not (Unix32.file_exists file_diskname)
         then
           Unix32.create_sparsefile file_diskname writable
         else
diff -a -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/utils/lib/unix32.ml ./src/utils/lib/unix32.ml
--- ./src/utils/lib/unix32.ml	2006-02-20 02:30:19.000000000 +0100
+++ ./src/utils/lib/unix32.ml	2006-03-06 18:56:46.000000000 +0100
@@ -205,11 +205,7 @@
     let getsize64 t =
       try
       check_destroyed t;
-      let was_closed = is_closed t in
-      let s = Unix2.c_getfdsize64 (local_force_fd t) in
-      if was_closed then
-        close t;
-      s
+      Unix2.c_getfdsize64 (local_force_fd t)
       with e ->
       if !verbose then lprintf_nl "Exception in FDCache.getsize64 %s: %s"
         t.filename
@@ -331,8 +327,8 @@
     val remove : t -> unit
     val read : t -> int64 -> string -> int -> int -> unit
     val write : t -> int64 -> string -> int -> int -> unit
-      
     val destroy : t -> unit
+    val is_closed : t -> bool
   end
 
 
@@ -359,6 +355,7 @@
     let read = FDCache.read
     let write = FDCache.write
     let destroy = FDCache.destroy
+    let is_closed = FDCache.is_closed
   end
 
 let zero_chunk_len = 65536L
@@ -653,6 +650,7 @@
       (try Unix.utimes t.dirname time time with _ -> ());
       ()
 
+    let is_closed _ = false
   end
 
 module SparseFile = struct
@@ -679,6 +677,8 @@
         len = zero_chunk_len;
         fd = zero_chunk_fd ();
       }
+
+    let is_closed _ = false
     
     let create filename writable =
 (*      lprintf_nl "SparseFile.create %s" filename; *)
@@ -1090,6 +1090,18 @@
 
 let table = H.create 100
 
+let destroyed t = t.file_kind = Destroyed
+  
+let fd_exists f =
+  try
+    let fd = H.find table { dummy with filename = f } in
+    match fd.file_kind with
+    | DiskFile fd -> not (DiskFile.is_closed fd)
+    | MultiFile fd -> not (MultiFile.is_closed fd)
+    | SparseFile fd -> not (SparseFile.is_closed fd)
+    | Destroyed -> false
+  with Not_found -> false
+
 let create f writable creator =
   try
     let fd = H.find table { dummy with filename = f; writable = writable } in
@@ -1367,15 +1379,32 @@
   | SparseFile t -> SparseFile.remove t
   | Destroyed -> failwith "Unix32.remove on destroyed FD"
       
-let getsize s =  getsize64 (create_ro s)
-let mtime s =  mtime64 (create_ro s)
+let getsize s =
+  let old_fd_exists = fd_exists s in
+  let fd = create_ro s in
+  let size = getsize64 fd in
+  if not old_fd_exists then close fd;
+  size
+
+let mtime s =
+  let old_fd_exists = fd_exists s in
+  let fd = create_ro s in
+  let time = mtime64 fd in
+  if not old_fd_exists then close fd;
+  time
 
-let file_exists s = 
-  (* We use this instead of Sys.file_exists, in case exists has side
-     effects ? *)
-  try 
-    exists (create_ro s)
-  with Unix.Unix_error (Unix.ENOENT, _, _) -> false
+let file_exists s =
+  let old_fd_exists = fd_exists s in
+    try
+      let fd = create_ro s in
+      let exists =
+        try
+          exists fd
+        with Unix.Unix_error (Unix.ENOENT, _, _) -> false
+      in
+      if not old_fd_exists then close fd;
+      exists
+    with Unix.Unix_error (Unix.ENOENT, _, _) -> false
 
 let rename t f =
   flush_fd t;
@@ -1565,6 +1594,8 @@
     let create_rw filename = 
       create (create_rw filename)
 
+    let is_closed = FDCache.is_closed
+
 (*
 (* the new part (shared_begin, shared_len) is shared between t1 and t2.
 It will be kept inside t1, and used by t2. The problem is what happens
@@ -1575,8 +1606,6 @@
       ()
 *)      
   end
-let destroyed t = t.file_kind = Destroyed
-  
 type t = file
 
 (*
