← Back to team overview

usb-creator-hackers team mailing list archive

[Merge] lp:~marcobiscaro2112/usb-creator/fix-1731977 into lp:usb-creator

 

Marco Biscaro has proposed merging lp:~marcobiscaro2112/usb-creator/fix-1731977 into lp:usb-creator.

Requested reviews:
  usb-creator hackers (usb-creator-hackers)

For more details, see:
https://code.launchpad.net/~marcobiscaro2112/usb-creator/fix-1731977/+merge/333638

This change ensures that the changes are written to disk before publishing the new progress.

I think that doing a fsync for each progress change is good enough to have a correct progress and not hurt performance.

In fact, I've benchmarked this change twice and doing a periodic fsync results in better performance in my case:

Without fsync: 6m51s / 6m30s
With fsync: 3m32s / 3m31s

-- 
Your team usb-creator hackers is requested to review the proposed merge of lp:~marcobiscaro2112/usb-creator/fix-1731977 into lp:usb-creator.
=== modified file 'bin/usb-creator-helper'
--- bin/usb-creator-helper	2016-01-22 19:38:17 +0000
+++ bin/usb-creator-helper	2017-11-13 17:20:45 +0000
@@ -120,9 +120,12 @@
         while(data):
             dst.write(data)
             written += len(data)
-            # TODO: find a way to display progress without buffering
             new_progress = int(written / src_size * 100.0)
             if new_progress != current_progress:
+                # flush buffers and sync before notifying the new progress
+                dst.flush()
+                os.fsync(dst.fileno())
+
                 self.Progress(new_progress)
                 current_progress = new_progress
             data = src.read(block_size)