/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/lockdir.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-17 00:47:52 UTC
  • mfrom: (7182 work)
  • mto: This revision was merged to the branch mainline in revision 7305.
  • Revision ID: jelmer@jelmer.uk-20181117004752-6ywampe5pfywlby4
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
    )
125
125
from .decorators import only_raises
126
126
from .errors import (
127
 
        DirectoryNotEmpty,
128
 
        FileExists,
129
 
        LockBreakMismatch,
130
 
        LockBroken,
131
 
        LockContention,
132
 
        LockCorrupt,
133
 
        LockFailed,
134
 
        LockNotHeld,
135
 
        NoSuchFile,
136
 
        PathError,
137
 
        ResourceBusy,
138
 
        TransportError,
139
 
        )
 
127
    DirectoryNotEmpty,
 
128
    FileExists,
 
129
    LockBreakMismatch,
 
130
    LockBroken,
 
131
    LockContention,
 
132
    LockCorrupt,
 
133
    LockFailed,
 
134
    LockNotHeld,
 
135
    NoSuchFile,
 
136
    PathError,
 
137
    ResourceBusy,
 
138
    TransportError,
 
139
    )
140
140
from .i18n import gettext
141
141
from .osutils import format_delta, rand_chars, get_host_name
142
142
from .sixish import (
171
171
 
172
172
    __INFO_NAME = '/info'
173
173
 
174
 
    def __init__(self, transport, path, file_modebits=0o644, dir_modebits=0o755,
175
 
        extra_holder_info=None):
 
174
    def __init__(self, transport, path, file_modebits=0o644,
 
175
                 dir_modebits=0o755, extra_holder_info=None):
176
176
        """Create a new LockDir object.
177
177
 
178
178
        The LockDir is initially unlocked - this just creates the object.
251
251
                self._trace("other holder is %r" % other_holder)
252
252
                try:
253
253
                    self._handle_lock_contention(other_holder)
254
 
                except:
 
254
                except BaseException:
255
255
                    self._remove_pending_dir(tmpname)
256
256
                    raise
257
257
            except Exception as e:
273
273
        self._trace("after locking, info=%r", info)
274
274
        if info is None:
275
275
            raise LockFailed(self, "lock was renamed into place, but "
276
 
                "now is missing!")
 
276
                             "now is missing!")
277
277
        if info.get('nonce') != self.nonce:
278
278
            self._trace("rename succeeded, "
279
 
                "but lock is still held by someone else")
 
279
                        "but lock is still held by someone else")
280
280
            raise LockContention(self)
281
281
        self._lock_held = True
282
282
        self._trace("... lock succeeded after %dms",
283
 
                (time.time() - start_time) * 1000)
 
283
                    (time.time() - start_time) * 1000)
284
284
        return self.nonce
285
285
 
286
286
    def _handle_lock_contention(self, other_holder):
340
340
        # We'll rename the whole directory into place to get atomic
341
341
        # properties
342
342
        self.transport.put_bytes_non_atomic(tmpname + self.__INFO_NAME,
343
 
            info.to_bytes())
 
343
                                            info.to_bytes())
344
344
        return tmpname
345
345
 
346
346
    @only_raises(LockNotHeld, LockBroken)
369
369
            self.transport.delete(tmpname + self.__INFO_NAME)
370
370
            try:
371
371
                self.transport.rmdir(tmpname)
372
 
            except DirectoryNotEmpty as e:
 
372
            except DirectoryNotEmpty:
373
373
                # There might have been junk left over by a rename that moved
374
374
                # another locker within the 'held' directory.  do a slower
375
375
                # deletion where we list the directory and remove everything
376
376
                # within it.
377
377
                self._trace("doing recursive deletion of non-empty directory "
378
 
                        "%s", tmpname)
 
378
                            "%s", tmpname)
379
379
                self.transport.delete_tree(tmpname)
380
380
            self._trace("... unlock succeeded after %dms",
381
 
                    (time.time() - start_time) * 1000)
 
381
                        (time.time() - start_time) * 1000)
382
382
            result = lock.LockResult(self.transport.abspath(self.path),
383
383
                                     old_nonce)
384
384
            for hook in self.hooks['lock_released']:
406
406
            if ui.ui_factory.confirm_action(
407
407
                u"Break %(lock_info)s",
408
408
                'breezy.lockdir.break',
409
 
                dict(lock_info=text_type(holder_info))):
 
409
                    dict(lock_info=text_type(holder_info))):
410
410
                result = self.force_break(holder_info)
411
411
                ui.ui_factory.show_message(
412
412
                    "Broke lock %s" % result.lock_url)
529
529
            info = self._read_info_file(self._held_info_path)
530
530
            self._trace("peek -> held")
531
531
            return info
532
 
        except NoSuchFile as e:
 
532
        except NoSuchFile:
533
533
            self._trace("peek -> not held")
534
534
 
535
535
    def _prepare_info(self):
549
549
            raise LockContention(self)
550
550
        result = self._attempt_lock()
551
551
        hook_result = lock.LockResult(self.transport.abspath(self.path),
552
 
                self.nonce)
 
552
                                      self.nonce)
553
553
        for hook in self.hooks['lock_acquired']:
554
554
            hook(hook_result)
555
555
        return result
616
616
                    start = gettext('Lock owner changed for')
617
617
                last_info = new_info
618
618
                msg = gettext('{0} lock {1} {2}.').format(start, lock_url,
619
 
                                                                    new_info)
 
619
                                                          new_info)
620
620
                if deadline_str is None:
621
621
                    deadline_str = time.strftime('%H:%M:%S',
622
 
                                                    time.localtime(deadline))
 
622
                                                 time.localtime(deadline))
623
623
                if timeout > 0:
624
624
                    msg += '\n' + gettext(
625
 
                             'Will continue to try until %s, unless '
626
 
                             'you press Ctrl-C.') % deadline_str
 
625
                        'Will continue to try until %s, unless '
 
626
                        'you press Ctrl-C.') % deadline_str
627
627
                msg += '\n' + gettext('See "brz help break-lock" for more.')
628
628
                self._report_function(msg)
629
629
            if (max_attempts is not None) and (attempt_count >= max_attempts):
681
681
        # we can't rely on that remotely.  Once this is cleaned up,
682
682
        # reenable this warning to prevent it coming back in
683
683
        # -- mbp 20060303
684
 
        ## warn("LockDir.lock_read falls back to write lock")
 
684
        # warn("LockDir.lock_read falls back to write lock")
685
685
        if self._lock_held or self._fake_read_lock:
686
686
            raise LockContention(self)
687
687
        self._fake_read_lock = True
733
733
    def __unicode__(self):
734
734
        """Return a user-oriented description of this object."""
735
735
        d = self.to_readable_dict()
736
 
        return ( gettext(
 
736
        return (gettext(
737
737
            u'held by %(user)s on %(hostname)s (process #%(pid)s), '
738
738
            u'acquired %(time_ago)s') % d)
739
739
 
796
796
        except ValueError as e:
797
797
            mutter('Corrupt lock info file: %r', lines)
798
798
            raise LockCorrupt("could not parse lock info file: " + str(e),
799
 
                lines)
 
799
                              lines)
800
800
        if stanza is None:
801
801
            # see bug 185013; we fairly often end up with the info file being
802
802
            # empty after an interruption; we could log a message here but
855
855
            pid = int(pid_str)
856
856
        except ValueError:
857
857
            mutter("can't parse pid %r from %r"
858
 
                % (pid_str, self))
 
858
                   % (pid_str, self))
859
859
            return False
860
860
        return osutils.is_local_pid_dead(pid)
861
861