mldonkey-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Mldonkey-commits] mldonkey distrib/ChangeLog src/daemon/common/co...


From: mldonkey-commits
Subject: [Mldonkey-commits] mldonkey distrib/ChangeLog src/daemon/common/co...
Date: Mon, 06 Mar 2006 17:59:45 +0000

CVSROOT:        /sources/mldonkey
Module name:    mldonkey
Branch:         
Changes by:     spiralvoice <address@hidden>    06/03/06 17:59:45

Modified files:
        distrib        : ChangeLog 
        src/daemon/common: commonOptions.ml 
        src/networks/donkey: donkeyGlobals.ml 
        src/utils/lib  : unix32.ml 

Log message:
        patch #4950

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/distrib/ChangeLog.diff?tr1=1.760&tr2=1.761&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/daemon/common/commonOptions.ml.diff?tr1=1.130&tr2=1.131&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/donkey/donkeyGlobals.ml.diff?tr1=1.75&tr2=1.76&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/utils/lib/unix32.ml.diff?tr1=1.58&tr2=1.59&r1=text&r2=text

Patches:
Index: mldonkey/distrib/ChangeLog
diff -u mldonkey/distrib/ChangeLog:1.760 mldonkey/distrib/ChangeLog:1.761
--- mldonkey/distrib/ChangeLog:1.760    Sun Mar  5 10:43:46 2006
+++ mldonkey/distrib/ChangeLog  Mon Mar  6 17:59:44 2006
@@ -14,6 +14,9 @@
 ChangeLog
 =========
 
+2006/03/06
+4950: Close unneeded file descriptors
+
 2006/03/05
 4946: System-wide cookies and referers option
 - MLDonkey will not move data from bittorrent.ini to downloads.ini
Index: mldonkey/src/daemon/common/commonOptions.ml
diff -u mldonkey/src/daemon/common/commonOptions.ml:1.130 
mldonkey/src/daemon/common/commonOptions.ml:1.131
--- mldonkey/src/daemon/common/commonOptions.ml:1.130   Sun Mar  5 10:43:46 2006
+++ mldonkey/src/daemon/common/commonOptions.ml Mon Mar  6 17:59:44 2006
@@ -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;
Index: mldonkey/src/networks/donkey/donkeyGlobals.ml
diff -u mldonkey/src/networks/donkey/donkeyGlobals.ml:1.75 
mldonkey/src/networks/donkey/donkeyGlobals.ml:1.76
--- mldonkey/src/networks/donkey/donkeyGlobals.ml:1.75  Thu Feb  9 11:41:39 2006
+++ mldonkey/src/networks/donkey/donkeyGlobals.ml       Mon Mar  6 17:59:45 2006
@@ -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
Index: mldonkey/src/utils/lib/unix32.ml
diff -u mldonkey/src/utils/lib/unix32.ml:1.58 
mldonkey/src/utils/lib/unix32.ml:1.59
--- mldonkey/src/utils/lib/unix32.ml:1.58       Mon Feb 20 01:30:19 2006
+++ mldonkey/src/utils/lib/unix32.ml    Mon Mar  6 17:59:45 2006
@@ -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
 
 (*




reply via email to

[Prev in Thread] Current Thread [Next in Thread]