1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- #$Id: back_anydbm.py,v 1.94 2002-12-11 01:03:38 richard Exp $
18+ #$Id: back_anydbm.py,v 1.95 2002-12-12 09:31:04 richard Exp $
1919'''
2020This module defines a backend that saves the hyperdatabase in a database
2121chosen by anydbm. It is guaranteed to always be available in python
2828from blobfiles import FileStorage
2929from sessions import Sessions
3030from roundup .indexer import Indexer
31- from locking import acquire_lock , release_lock
31+ from roundup . backends import locking
3232from roundup .hyperdb import String , Password , Date , Interval , Link , \
3333 Multilink , DatabaseError , Boolean , Number
3434
@@ -72,6 +72,12 @@ def __init__(self, config, journaltag=None):
7272 # ensure files are group readable and writable
7373 os .umask (0002 )
7474
75+ # lock it
76+ lockfilenm = os .path .join (self .dir , 'lock' )
77+ self .lockfile = locking .acquire_lock (lockfilenm )
78+ self .lockfile .write (str (os .getpid ()))
79+ self .lockfile .flush ()
80+
7581 def post_init (self ):
7682 ''' Called once the schema initialisation has finished.
7783 '''
@@ -203,20 +209,13 @@ def opendb(self, name, mode):
203209 mode )
204210 return dbm .open (path , mode )
205211
206- def lockdb (self , name ):
207- ''' Lock a database file
208- '''
209- path = os .path .join (os .getcwd (), self .dir , '%s.lock' % name )
210- return acquire_lock (path )
211-
212212 #
213213 # Node IDs
214214 #
215215 def newid (self , classname ):
216216 ''' Generate a new id for the given class
217217 '''
218218 # open the ids DB - create if if doesn't exist
219- lock = self .lockdb ('_ids' )
220219 db = self .opendb ('_ids' , 'c' )
221220 if db .has_key (classname ):
222221 newid = db [classname ] = str (int (db [classname ]) + 1 )
@@ -225,18 +224,15 @@ def newid(self, classname):
225224 newid = str (self .getclass (classname ).count ()+ 1 )
226225 db [classname ] = newid
227226 db .close ()
228- release_lock (lock )
229227 return newid
230228
231229 def setid (self , classname , setid ):
232230 ''' Set the id counter: used during import of database
233231 '''
234232 # open the ids DB - create if if doesn't exist
235- lock = self .lockdb ('_ids' )
236233 db = self .opendb ('_ids' , 'c' )
237234 db [classname ] = str (setid )
238235 db .close ()
239- release_lock (lock )
240236
241237 #
242238 # Nodes
@@ -696,7 +692,11 @@ def rollback(self):
696692 def close (self ):
697693 ''' Nothing to do
698694 '''
699- pass
695+ if self .lockfile is not None :
696+ locking .release_lock (self .lockfile )
697+ if self .lockfile is not None :
698+ self .lockfile .close ()
699+ self .lockfile = None
700700
701701_marker = []
702702class Class (hyperdb .Class ):
@@ -1326,7 +1326,7 @@ def is_retired(self, nodeid):
13261326
13271327 def destroy (self , nodeid ):
13281328 '''Destroy a node.
1329-
1329+
13301330 WARNING: this method should never be used except in extremely rare
13311331 situations where there could never be links to the node being
13321332 deleted
@@ -1906,13 +1906,12 @@ def import_list(self, propnames, proplist):
19061906 def get (self , nodeid , propname , default = _marker , cache = 1 ):
19071907 ''' trap the content propname and get it from the file
19081908 '''
1909-
1910- poss_msg = 'Possibly a access right configuration problem.'
1909+ poss_msg = 'Possibly an access right configuration problem.'
19111910 if propname == 'content' :
19121911 try :
19131912 return self .db .getfile (self .classname , nodeid , None )
19141913 except IOError , (strerror ):
1915- # BUG: by catching this we donot see an error in the log.
1914+ # XXX by catching this we donot see an error in the log.
19161915 return 'ERROR reading file: %s%s\n %s\n %s' % (
19171916 self .classname , nodeid , poss_msg , strerror )
19181917 if default is not _marker :
0 commit comments