~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

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
231
232
    def _close(self):
232
233
        """A hook point for subclasses that need to take action on close."""
233
234
 
234
 
    def close(self):
 
235
    def close(self, want_fdatasync=False):
 
236
        if want_fdatasync:
 
237
            try:
 
238
                self.fdatasync()
 
239
            except errors.TransportNotPossible:
 
240
                pass
235
241
        self._close()
236
242
        del _file_streams[self.transport.abspath(self.relpath)]
237
243
 
 
244
    def fdatasync(self):
 
245
        """Force data out to physical disk if possible.
 
246
 
 
247
        :raises TransportNotPossible: If this transport has no way to 
 
248
            flush to disk.
 
249
        """
 
250
        raise errors.TransportNotPossible(
 
251
            "%s cannot fdatasync" % (self.transport,))
 
252
 
238
253
 
239
254
class FileFileStream(FileStream):
240
255
    """A file stream object returned by open_write_stream.
249
264
    def _close(self):
250
265
        self.file_handle.close()
251
266
 
 
267
    def fdatasync(self):
 
268
        """Force data out to physical disk if possible."""
 
269
        self.file_handle.flush()
 
270
        try:
 
271
            fileno = self.file_handle.fileno()
 
272
        except AttributeError:
 
273
            raise errors.TransportNotPossible()
 
274
        osutils.fdatasync(fileno)
 
275
 
252
276
    def write(self, bytes):
253
277
        osutils.pump_string_file(bytes, self.file_handle)
254
278