[Zodb-checkins] CVS: Zope3/lib/python/ZODB - lock_file.py:1.9

Jeremy Hylton jeremy@zope.com
Tue, 3 Dec 2002 13:52:08 -0500


Update of /cvs-repository/Zope3/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv25153

Modified Files:
	lock_file.py 
Log Message:
Don't use default argument to specify exception.
Log message on platforms where file-locking isn't supported.


=== Zope3/lib/python/ZODB/lock_file.py 1.8 => 1.9 ===
--- Zope3/lib/python/ZODB/lock_file.py:1.8	Thu Jul 18 18:35:30 2002
+++ Zope3/lib/python/ZODB/lock_file.py	Tue Dec  3 13:52:08 2002
@@ -2,51 +2,57 @@
 #
 # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
 # All Rights Reserved.
-# 
+#
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-# 
+# FOR A PARTICULAR PURPOSE
+#
 ##############################################################################
+
 from ZODB.POSException import StorageSystemError
 
-# Try to create a function that creates Unix file locks.  On windows
-# this will fail.
+# Try to create a function that creates Unix file locks.
 try:
     import fcntl
 
     lock_file_FLAG = fcntl.LOCK_EX | fcntl.LOCK_NB
 
-    def lock_file(file, error=StorageSystemError):
+    def lock_file(file):
         try:
             un = file.fileno()
         except:
             return # don't care if not a real file
 
         try:
-            fcntl.flock(un,lock_file_FLAG)
+            fcntl.flock(un, lock_file_FLAG)
         except:
-            raise error("Could not lock %s" % file.name)
+            raise StorageSystemError, (
+                "Could not lock the database file.  There must be\n"
+                "another process that has opened the file.\n"
+                "<p>")
 
 except:
     # Try windows-specific code:
     try:
         from winlock import LockFile
-        def lock_file(file, error=StorageSystemError):
+        def lock_file(file):
             try:
-                un = file.fileno()
+                un=file.fileno()
             except:
                 return # don't care if not a real file
-            
+
             try:
                 LockFile(un, 0, 0, 1, 0) # just lock the first byte, who cares
             except:
-                raise error("Could not lock %s" % file.name)
+                raise StorageSystemError, (
+                    "Could not lock the database file.  There must be\n"
+                    "another process that has opened the file.\n"
+                    "<p>")
     except:
-        def lock_file(file, error=None):
-            # XXX There really ought to be a zLOG warning here.
-            pass
-    
+        import zLOG
+        def lock_file(file):
+            zLOG.LOG("FS", zLOG.INFO,
+                     "No file-locking support on this platform")