~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lock.py

  • Committer: Martin Pool
  • Date: 2005-06-06 05:13:21 UTC
  • Revision ID: mbp@sourcefrog.net-20050606051321-096739d92aa50664
- make sure bzr is always explicitly invoked through 
  python in case it's not executable

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
"""
36
36
 
37
37
 
38
 
import sys
39
 
import os
 
38
import sys, os
40
39
 
41
 
from bzrlib.trace import mutter, note, warning
42
 
from bzrlib.errors import LockError
 
40
from trace import mutter, note, warning
 
41
from errors import LockError
43
42
 
44
43
class _base_Lock(object):
45
44
    def _open(self, filename, filemode):
46
 
        import errno
47
 
        try:
48
 
            self.f = open(filename, filemode)
49
 
            return self.f
50
 
        except IOError, e:
51
 
            if e.errno != errno.ENOENT:
52
 
                raise
53
 
 
54
 
            # maybe this is an old branch (before may 2005)
55
 
            mutter("trying to create missing branch lock %r" % filename)
56
 
            
57
 
            self.f = open(filename, 'wb')
58
 
            return self.f
59
 
 
 
45
        self.f = open(filename, filemode)
 
46
        return self.f
 
47
    
60
48
 
61
49
    def __del__(self):
62
50
        if self.f:
63
51
            from warnings import warn
64
52
            warn("lock on %r not released" % self.f)
65
53
            self.unlock()
66
 
            
67
54
 
68
55
    def unlock(self):
69
56
        raise NotImplementedError()
198
185
                        fpos = os.lseek(fn, 0,0)
199
186
                        os.lseek(fn, 0,0)
200
187
 
201
 
                    if flags & _msvc_FileLock.LOCK_SH:
202
 
                        if flags & _msvc_FileLock.LOCK_NB:
 
188
                    if flags & self.LOCK_SH:
 
189
                        if flags & self.LOCK_NB:
203
190
                            lock_mode = msvcrt.LK_NBLCK
204
191
                        else:
205
192
                            lock_mode = msvcrt.LK_LOCK
206
 
                    elif flags & _msvc_FileLock.LOCK_EX:
207
 
                        if flags & _msvc_FileLock.LOCK_NB:
 
193
                    elif flags & self.LOCK_EX:
 
194
                        if flags & self.LOCK_NB:
208
195
                            lock_mode = msvcrt.LK_NBRLCK
209
196
                        else:
210
197
                            lock_mode = msvcrt.LK_RLCK