~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-11 15:25:32 UTC
  • mfrom: (1993.1.2 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060911152532-3762ad5c8c6c98dd
(jam) save a round trip during locking using put_bytes_non_atomic

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 RioWriter, read_stanza, Stanza
 
117
from bzrlib.rio import 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
200
200
                # After creating the lock directory, try again
201
201
                self.transport.mkdir(tmpname)
202
202
 
203
 
            sio = StringIO()
204
 
            self._prepare_info(sio)
205
 
            sio.seek(0)
206
 
            # append will create a new file; we use append rather than put
207
 
            # because we don't want to write to a temporary file and rename
208
 
            # into place, because that's going to happen to the whole
209
 
            # directory
210
 
            self.transport.append_file(tmpname + self.__INFO_NAME, sio)
 
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)
211
210
 
212
211
            self.transport.rename(tmpname, self._held_dir)
213
212
            self._lock_held = True
336
335
        except NoSuchFile, e:
337
336
            return None
338
337
 
339
 
    def _prepare_info(self, outf):
 
338
    def _prepare_info(self):
340
339
        """Write information about a pending lock to a temporary file.
341
340
        """
342
341
        import socket
348
347
                   nonce=self.nonce,
349
348
                   user=config.user_email(),
350
349
                   )
351
 
        RioWriter(outf).write_stanza(s)
 
350
        return s.to_string()
352
351
 
353
352
    def _parse_info(self, info_file):
354
353
        return read_stanza(info_file.readlines()).as_dict()