/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to brzlib/lockable_files.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from .lazy_import import lazy_import
 
17
from __future__ import absolute_import
 
18
 
 
19
from brzlib.lazy_import import lazy_import
18
20
lazy_import(globals(), """
19
 
from breezy import (
 
21
import warnings
 
22
 
 
23
from brzlib import (
20
24
    counted_lock,
 
25
    errors,
21
26
    lock,
 
27
    osutils,
22
28
    transactions,
23
29
    urlutils,
24
30
    )
25
31
""")
26
32
 
27
 
from . import (
28
 
    errors,
29
 
    )
30
 
from .decorators import (
 
33
from brzlib.decorators import (
31
34
    only_raises,
32
35
    )
33
36
 
99
102
 
100
103
    def _escape(self, file_or_path):
101
104
        """DEPRECATED: Do not use outside this class"""
 
105
        if not isinstance(file_or_path, basestring):
 
106
            file_or_path = '/'.join(file_or_path)
102
107
        if file_or_path == '':
103
108
            return u''
104
 
        return urlutils.escape(file_or_path)
 
109
        return urlutils.escape(osutils.safe_unicode(file_or_path))
105
110
 
106
111
    def _find_modes(self):
107
112
        """Determine the appropriate modes for files and directories.
114
119
        try:
115
120
            st = self._transport.stat('.')
116
121
        except errors.TransportNotPossible:
117
 
            self._dir_mode = 0o755
118
 
            self._file_mode = 0o644
 
122
            self._dir_mode = 0755
 
123
            self._file_mode = 0644
119
124
        else:
120
125
            # Check the directory mode, but also make sure the created
121
126
            # directories and files are read-write for this user. This is
122
127
            # mostly a workaround for filesystems which lie about being able to
123
128
            # write to a directory (cygwin & win32)
124
 
            self._dir_mode = (st.st_mode & 0o7777) | 0o0700
 
129
            self._dir_mode = (st.st_mode & 07777) | 00700
125
130
            # Remove the sticky and execute bits for files
126
 
            self._file_mode = self._dir_mode & ~0o7111
 
131
            self._file_mode = self._dir_mode & ~07111
127
132
 
128
133
    def leave_in_place(self):
129
134
        """Set this LockableFiles to not clear the physical lock on unlock."""
150
155
        """
151
156
        if self._lock_mode:
152
157
            if (self._lock_mode != 'w'
153
 
                    or not self.get_transaction().writeable()):
 
158
                or not self.get_transaction().writeable()):
154
159
                raise errors.ReadOnlyError(self)
155
160
            self._lock.validate_token(token)
156
161
            self._lock_count += 1
157
162
            return self._token_from_lock
158
163
        else:
159
164
            token_from_lock = self._lock.lock_write(token=token)
160
 
            # traceback.print_stack()
 
165
            #traceback.print_stack()
161
166
            self._lock_mode = 'w'
162
167
            self._lock_count = 1
163
168
            self._set_write_transaction()
171
176
            self._lock_count += 1
172
177
        else:
173
178
            self._lock.lock_read()
174
 
            # traceback.print_stack()
 
179
            #traceback.print_stack()
175
180
            self._lock_mode = 'r'
176
181
            self._lock_count = 1
177
182
            self._set_read_transaction()
193
198
        if self._lock_count > 1:
194
199
            self._lock_count -= 1
195
200
        else:
196
 
            # traceback.print_stack()
 
201
            #traceback.print_stack()
197
202
            self._finish_transaction()
198
203
            try:
199
204
                self._lock.unlock()
200
205
            finally:
201
 
                self._lock_count = 0
202
 
                self._lock_mode = None
 
206
                self._lock_mode = self._lock_count = None
203
207
 
204
208
    def is_locked(self):
205
209
        """Return true if this LockableFiles group is locked"""
256
260
    This is suitable for use only in WorkingTrees (which are at present
257
261
    always local).
258
262
    """
259
 
 
260
263
    def __init__(self, transport, escaped_name, file_modebits, dir_modebits):
261
264
        self._transport = transport
262
265
        self._escaped_name = escaped_name
290
293
    def create(self, mode=None):
291
294
        """Create lock mechanism"""
292
295
        # for old-style locks, create the file now
293
 
        self._transport.put_bytes(self._escaped_name, b'',
294
 
                                  mode=self._file_modebits)
 
296
        self._transport.put_bytes(self._escaped_name, '',
 
297
                            mode=self._file_modebits)
295
298
 
296
299
    def validate_token(self, token):
297
300
        if token is not None: