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

Proposed by Marco Biscaro
Status: Merged
Merge reported by: Marc Deslauriers
Merged at revision: not available
Proposed branch: lp:~marcobiscaro2112/usb-creator/fix-1731977
Merge into: lp:usb-creator
Diff against target: 17 lines (+4/-1)
1 file modified
bin/usb-creator-helper (+4/-1)
To merge this branch: bzr merge lp:~marcobiscaro2112/usb-creator/fix-1731977
Reviewer Review Type Date Requested Status
Marc Deslauriers Approve
Review via email: mp+333638@code.launchpad.net

Description of the change

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

To post a comment you must log in.
Revision history for this message
Marc Deslauriers (mdeslaur) wrote :

Looks good, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/usb-creator-helper'
2--- bin/usb-creator-helper 2016-01-22 19:38:17 +0000
3+++ bin/usb-creator-helper 2017-11-13 17:20:45 +0000
4@@ -120,9 +120,12 @@
5 while(data):
6 dst.write(data)
7 written += len(data)
8- # TODO: find a way to display progress without buffering
9 new_progress = int(written / src_size * 100.0)
10 if new_progress != current_progress:
11+ # flush buffers and sync before notifying the new progress
12+ dst.flush()
13+ os.fsync(dst.fileno())
14+
15 self.Progress(new_progress)
16 current_progress = new_progress
17 data = src.read(block_size)

Subscribers

People subscribed via source and target branches