~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-02 04:09:08 UTC
  • mfrom: (6046.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20110802040908-hqz2wr82nyrk14gk
(mbp) merge 2.3 and 2.4 to trunk (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
"""
28
28
 
29
29
from cStringIO import StringIO
 
30
import os
30
31
import sys
31
32
 
32
33
from bzrlib.lazy_import import lazy_import
227
228
    def _close(self):
228
229
        """A hook point for subclasses that need to take action on close."""
229
230
 
230
 
    def close(self):
 
231
    def close(self, want_fdatasync=False):
 
232
        if want_fdatasync:
 
233
            try:
 
234
                self.fdatasync()
 
235
            except errors.TransportNotPossible:
 
236
                pass
231
237
        self._close()
232
238
        del _file_streams[self.transport.abspath(self.relpath)]
233
239
 
 
240
    def fdatasync(self):
 
241
        """Force data out to physical disk if possible.
 
242
 
 
243
        :raises TransportNotPossible: If this transport has no way to 
 
244
            flush to disk.
 
245
        """
 
246
        raise errors.TransportNotPossible(
 
247
            "%s cannot fdatasync" % (self.transport,))
 
248
 
234
249
 
235
250
class FileFileStream(FileStream):
236
251
    """A file stream object returned by open_write_stream.
245
260
    def _close(self):
246
261
        self.file_handle.close()
247
262
 
 
263
    def fdatasync(self):
 
264
        """Force data out to physical disk if possible."""
 
265
        self.file_handle.flush()
 
266
        try:
 
267
            fileno = self.file_handle.fileno()
 
268
        except AttributeError:
 
269
            raise errors.TransportNotPossible()
 
270
        osutils.fdatasync(fileno)
 
271
 
248
272
    def write(self, bytes):
249
273
        osutils.pump_string_file(bytes, self.file_handle)
250
274