~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lock.py

 * bzr add now lists how many files were ignored per glob.  add --verbose
   lists the specific files.  (Aaron Bentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
unlock() method.
35
35
"""
36
36
 
37
 
import errno
 
37
 
 
38
import sys
38
39
import os
39
 
import sys
40
40
 
41
41
from bzrlib.trace import mutter, note, warning
42
42
from bzrlib.errors import LockError
43
43
 
44
44
class _base_Lock(object):
45
45
    def _open(self, filename, filemode):
 
46
        import errno
46
47
        try:
47
48
            self.f = open(filename, filemode)
48
49
            return self.f
53
54
            # maybe this is an old branch (before may 2005)
54
55
            mutter("trying to create missing branch lock %r", filename)
55
56
            
56
 
            self.f = open(filename, 'wb+')
 
57
            self.f = open(filename, 'wb')
57
58
            return self.f
58
59
 
 
60
 
59
61
    def __del__(self):
60
62
        if self.f:
61
63
            from warnings import warn
62
64
            warn("lock on %r not released" % self.f)
63
65
            self.unlock()
64
66
            
 
67
 
65
68
    def unlock(self):
66
69
        raise NotImplementedError()
67
70
 
85
88
            self.f.close()
86
89
            del self.f 
87
90
 
 
91
 
88
92
    class _fcntl_WriteLock(_fcntl_FileLock):
89
93
        def __init__(self, filename):
90
 
            # standard IO errors get exposed directly.
91
 
            self._open(filename, 'wb')
92
94
            try:
93
 
                fcntl.lockf(self.f, fcntl.LOCK_EX)
94
 
            except IOError, e:
95
 
                # we should be more precise about whats a locking
96
 
                # error and whats a random-other error
 
95
                fcntl.lockf(self._open(filename, 'wb'), fcntl.LOCK_EX)
 
96
            except Exception, e:
97
97
                raise LockError(e)
98
98
 
 
99
 
99
100
    class _fcntl_ReadLock(_fcntl_FileLock):
100
 
 
101
101
        def __init__(self, filename):
102
 
            # standard IO errors get exposed directly.
103
 
            self._open(filename, 'rb')
104
102
            try:
105
 
                fcntl.lockf(self.f, fcntl.LOCK_SH)
106
 
            except IOError, e:
107
 
                # we should be more precise about whats a locking
108
 
                # error and whats a random-other error
 
103
                fcntl.lockf(self._open(filename, 'rb'), fcntl.LOCK_SH)
 
104
            except Exception, e:
109
105
                raise LockError(e)
110
106
 
111
107
    WriteLock = _fcntl_WriteLock
112
108
    ReadLock = _fcntl_ReadLock
113
109
 
114
 
 
115
110
except ImportError:
116
111
    try:
117
112
        import win32con, win32file, pywintypes