MOON
Server: Apache/2.2.34 (Unix) mod_ssl/2.2.34 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 FrontPage/5.0.2.2635
System: Linux server.asjudinet.com 2.6.32-042stab141.3 #1 SMP Fri Nov 15 22:45:34 MSK 2019 i686
User: asjudine (504)
PHP: 5.2.17
Disabled: NONE
Upload Files
File: //proc/3/task/3/cwd/usr/lib/python2.4/Demo/pdist/cvslock.pyc
mò
‚=5Dc@sêdZdkZdkZdkZdkZdZdZdZdZdZ	dfd„ƒYZ
d	e
fd
„ƒYZdfd„ƒYZd
„Z
defd„ƒYZdefd„ƒYZed„Zd„ZedjoeƒndS(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
is#cvs.lcks	#cvs.rfl.s	#cvs.wfl.tErrorcBs#tZd„Zd„Zd„ZRS(NcCs
||_dS(N(tmsgtself(RR((t(/usr/lib/python2.4/Demo/pdist/cvslock.pyt__init__`scCs
t|iƒS(N(treprRR(R((Rt__repr__cscCs
t|iƒS(N(tstrRR(R((Rt__str__fs(t__name__t
__module__RRR(((RR^s		tLockedcBstZRS(N(R	R
(((RRjstLockcBsVtZded„Zd„Zd„Zd„Zd„Zd„Zd„Z	d	„Z
RS(
Nt.cCsx||_||_d|_d|_ttiƒƒ}|i
tƒ|_|i
t
|ƒ|_|i
t|ƒ|_dS(N(t
repositoryRtdelaytNonetlockdirtlockfileRtostgetpidtpidtjointCVSLCKtcvslcktCVSRFLtcvsrfltCVSWFLtcvswfl(RRRR((RRps				cCsdGH|iƒdS(Nt__del__(Rtunlock(R((RRzscCsÇxÀy'|i|_ti|idƒdSWqtij
o‚}d|_|dtjoFyti	|iƒ}Wntij
o
qnX|i|ƒqntd|i
|fƒ‚qXqWdS(Niiÿisfailed to lock %s: %s(RRRRtmkdirterrorRRtEEXISTtstattsttsleepRR(RR#R((Rt
setlockdir~s 	
cCs|iƒ|iƒdS(N(Rt
unlockfilet	unlockdir(R((RRs
cCsT|ioFdG|iGHyti|iƒWntij
onXd|_ndS(Ntunlink(RRRR(R R(R((RR&”s
cCsT|ioFdG|iGHyti|iƒWntij
onXd|_ndS(Ntrmdir(RRRR)R R(R((RR's
cCst||i|iƒdS(N(R$R#RRR(RR#((RR$¦scCstii|i|ƒS(N(RtpathRRRtname(RR+((RR©s(R	R
tDELAYRRR%RR&R'R$R(((RRns
								cCs£|djot|ƒ‚n|ti}yti|ƒ}|d}Wnt
j
od|}nXdtitiƒƒdd!Gd|G|GHti|ƒdS(Nisuid %ds[%s]iisWaiting for %s's lock in(RRR#R"tST_UIDtuidtpwdtgetpwuidtpwenttusertKeyErrorttimetctimeRR$(R#RRR.R1R2((RR$­s


tReadLockcBstZed„ZRS(NcCs|ti|||ƒd}z<|iƒ|i|_t	|idƒ}|iƒd}Wd|p|iƒn|i
ƒXdS(Nitwi(RRRRRtokR%RRtopentfptcloseR&R'(RRRR:R8((RR½s


(R	R
R,R(((RR6»st	WriteLockcBstZed„Zd„ZRS(NcCs€ti|||ƒ|iƒx4|iƒ}|pPn|iƒ|i	|ƒq W|i
|_t|idƒ}|iƒdS(NiR7(RRRRRR%t
readers_existR.R'R$RRR9R:R;(RRRR:R.((RRÎs

cCs~ttƒ}xkti|iƒD]W}|| tjo@yti|i	|ƒƒ}Wntij
o
qnX|SqqWdS(N(
tlenRtnRtlistdirRRR+R"RR#R R(RR+R?R#((RR=Ûs(R	R
R,RR=(((RR<Ìs
cCsmxfg}xE|D]<}y|it|dƒƒWqtj
o
}~PqXqWPt|i||ƒqWt
S(Nii(tlockstrepositoriestrtappendR<RtinstanceR$RRtlist(RBRRERARC((RtMultipleWriteLockçs
cCsõdk}|ido|id}nd}d}d}zDdGHt|ƒ}dGH|iƒdGHt|ƒ}dGH|iƒWddgGHd|_	dgGH|o|iƒndgGH|o|iƒndgGHd}d	gGHd}d
gGHXdS(NiR
sattempting write lock ...sgot it.sattempting read lock ...iiiii(
tsystargvRRtrltwlR<RR6t
exc_traceback(RRKRHRJ((Rttestös:	
	t__main__(t__doc__RR4R"R/R,R!RRRRRRR$R6R<RGRMR	(RR<R"RRRR$R,R6R/R!RGR4RMRRR((Rt?Gs&				?		!