~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-09-06 12:20:16 UTC
  • mfrom: (1551.8.23 Aaron's mergeable stuff)
  • Revision ID: pqm@pqm.ubuntu.com-20060906122016-54ab3159023ef544
Improve conflict message for deleting directories with contents

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2006 Canonical Ltd
2
 
 
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
96
96
 
97
97
import os
98
98
import time
99
 
from warnings import warn
100
99
from StringIO import StringIO
101
100
 
102
101
import bzrlib.config
106
105
        LockBreakMismatch,
107
106
        LockBroken,
108
107
        LockContention,
109
 
        LockError,
110
108
        LockNotHeld,
111
109
        NoSuchFile,
112
110
        PathError,
191
189
            raise UnlockableTransport(self.transport)
192
190
        try:
193
191
            tmpname = '%s/pending.%s.tmp' % (self.path, rand_chars(20))
194
 
            self.transport.mkdir(tmpname)
 
192
            try:
 
193
                self.transport.mkdir(tmpname)
 
194
            except NoSuchFile:
 
195
                # This may raise a FileExists exception
 
196
                # which is okay, it will be caught later and determined
 
197
                # to be a LockContention.
 
198
                self.create(mode=self._dir_modebits)
 
199
                
 
200
                # After creating the lock directory, try again
 
201
                self.transport.mkdir(tmpname)
 
202
 
195
203
            sio = StringIO()
196
204
            self._prepare_info(sio)
197
205
            sio.seek(0)
200
208
            # into place, because that's going to happen to the whole
201
209
            # directory
202
210
            self.transport.append(tmpname + self.__INFO_NAME, sio)
 
211
 
203
212
            self.transport.rename(tmpname, self._held_dir)
204
213
            self._lock_held = True
205
214
            self.confirm()
373
382
        self.attempt_lock()
374
383
 
375
384
    def lock_read(self):
376
 
        """Compatability-mode shared lock.
 
385
        """Compatibility-mode shared lock.
377
386
 
378
387
        LockDir doesn't support shared read-only locks, so this 
379
388
        just pretends that the lock is taken but really does nothing.