File: //proc/3/task/3/cwd/usr/lib/python2.4/Demo/pdist/cvslock.pyo
mò
‚=5Dc @ sê d Z d k Z d k Z d k Z d k Z d Z d Z d Z d Z d Z d f d „ ƒ YZ
d e
f d
„ ƒ YZ d f d „ ƒ YZ d
„ Z
d e f d „ ƒ YZ d e f d „ ƒ YZ e d „ Z d „ Z e d j o e ƒ n d S( sû CVS locking algorithm.
CVS locking strategy
====================
As reverse engineered from the CVS 1.3 sources (file lock.c):
- Locking is done on a per repository basis (but a process can hold
write locks for multiple directories); all lock files are placed in
the repository and have names beginning with "#cvs.".
- Before even attempting to lock, a file "#cvs.tfl.<pid>" is created
(and removed again), to test that we can write the repository. [The
algorithm can still be fooled (1) if the repository's mode is changed
while attempting to lock; (2) if this file exists and is writable but
the directory is not.]
- While creating the actual read/write lock files (which may exist for
a long time), a "meta-lock" is held. The meta-lock is a directory
named "#cvs.lock" in the repository. The meta-lock is also held while
a write lock is held.
- To set a read lock:
- acquire the meta-lock
- create the file "#cvs.rfl.<pid>"
- release the meta-lock
- To set a write lock:
- acquire the meta-lock
- check that there are no files called "#cvs.rfl.*"
- if there are, release the meta-lock, sleep, try again
- create the file "#cvs.wfl.<pid>"
- To release a write lock:
- remove the file "#cvs.wfl.<pid>"
- rmdir the meta-lock
- To release a read lock:
- remove the file "#cvs.rfl.<pid>"
Additional notes
----------------
- A process should read-lock at most one repository at a time.
- A process may write-lock as many repositories as it wishes (to avoid
deadlocks, I presume it should always lock them top-down in the
directory hierarchy).
- A process should make sure it removes all its lock files and
directories when it crashes.
- Limitation: one user id should not be committing files into the same
repository at the same time.
Turn this into Python code
--------------------------
rl = ReadLock(repository, waittime)
wl = WriteLock(repository, waittime)
list = MultipleWriteLock([repository1, repository2, ...], waittime)
Ni
i s #cvs.lcks #cvs.rfl.s #cvs.wfl.t Errorc B s# t Z d „ Z d „ Z d „ Z RS( Nc C s
| | _ d S( N( t msgt self( R R ( ( t( /usr/lib/python2.4/Demo/pdist/cvslock.pyt __init__` s c C s
t | i ƒ S( N( t reprR R ( R ( ( R t __repr__c s c C s
t | i ƒ S( N( t strR R ( R ( ( R t __str__f s ( t __name__t
__module__R R R ( ( ( R R ^ s t Lockedc B s t Z RS( N( R R
( ( ( R R j s t Lockc B sV t Z d e d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z
RS(
Nt .c C sx | | _ | | _ d | _ d | _ t t i ƒ ƒ } | i
t ƒ | _ | i
t
| ƒ | _ | i
t | ƒ | _ d S( N( t
repositoryR t delayt Nonet lockdirt lockfileR t ost getpidt pidt joint CVSLCKt cvslckt CVSRFLt cvsrflt CVSWFLt cvswfl( R R R R ( ( R R p s c C s d GH| i ƒ d S( Nt __del__( R t unlock( R ( ( R R z s c C sÇ xÀ y' | i | _ t i | i d ƒ d SWq t i j
o‚ } d | _ | d t j oF y t i | i ƒ } Wn t i j
o
q n X| i | ƒ q n t d | i
| f ƒ ‚ q Xq Wd S( Ni iÿ i s failed to lock %s: %s( R R R R t mkdirt errorR R t EEXISTt statt stt sleepR R ( R R# R ( ( R t
setlockdir~ s
c C s | i ƒ | i ƒ d S( N( R t
unlockfilet unlockdir( R ( ( R R s
c C sT | i oF d G| i GHy t i | i ƒ Wn t i j
o n Xd | _ n d S( Nt unlink( R R R R( R R ( R ( ( R R&