~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-31 16:12:57 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060731161257-91a231523255332c
new official bzr.ico

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
from bzrlib.trace import mutter
115
115
from bzrlib.transport import Transport
116
116
from bzrlib.osutils import rand_chars
117
 
from bzrlib.rio import read_stanza, Stanza
 
117
from bzrlib.rio import RioWriter, read_stanza, Stanza
118
118
 
119
119
# XXX: At the moment there is no consideration of thread safety on LockDir
120
120
# objects.  This should perhaps be updated - e.g. if two threads try to take a
189
189
            raise UnlockableTransport(self.transport)
190
190
        try:
191
191
            tmpname = '%s/pending.%s.tmp' % (self.path, rand_chars(20))
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
 
 
203
 
            info_bytes = self._prepare_info()
204
 
            # We use put_file_non_atomic because we just created a new unique
205
 
            # directory so we don't have to worry about files existing there.
206
 
            # We'll rename the whole directory into place to get atomic
207
 
            # properties
208
 
            self.transport.put_bytes_non_atomic(tmpname + self.__INFO_NAME,
209
 
                                                info_bytes)
210
 
 
 
192
            self.transport.mkdir(tmpname)
 
193
            sio = StringIO()
 
194
            self._prepare_info(sio)
 
195
            sio.seek(0)
 
196
            # append will create a new file; we use append rather than put
 
197
            # because we don't want to write to a temporary file and rename
 
198
            # into place, because that's going to happen to the whole
 
199
            # directory
 
200
            self.transport.append(tmpname + self.__INFO_NAME, sio)
211
201
            self.transport.rename(tmpname, self._held_dir)
212
202
            self._lock_held = True
213
203
            self.confirm()
335
325
        except NoSuchFile, e:
336
326
            return None
337
327
 
338
 
    def _prepare_info(self):
 
328
    def _prepare_info(self, outf):
339
329
        """Write information about a pending lock to a temporary file.
340
330
        """
341
331
        import socket
347
337
                   nonce=self.nonce,
348
338
                   user=config.user_email(),
349
339
                   )
350
 
        return s.to_string()
 
340
        RioWriter(outf).write_stanza(s)
351
341
 
352
342
    def _parse_info(self, info_file):
353
343
        return read_stanza(info_file.readlines()).as_dict()