/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 breezy/lockable_files.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

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