From 83ae3f1cbdb4caa0ff9c24f973a3256c960ef1f3 Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Tue, 30 Jun 2020 00:13:46 +0200 Subject: [PATCH] Linux: do not trust device write stats if higher than what we wrote For reasons unknown the device write statistics sometimes report higher numbers than the number of bytes we wrote to the device on some hardware. Causing write percentage in progressbar text to exceed 100% Maximize amount of bytes to what we wrote to the device. This do will result in unreliable write progress on these devices (it will then show amount of bytes written to cache instead of what made it to device yet) Closes #82 --- downloadthread.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/downloadthread.cpp b/downloadthread.cpp index d8d6c26..7972a90 100644 --- a/downloadthread.cpp +++ b/downloadthread.cpp @@ -515,7 +515,7 @@ uint64_t DownloadThread::verifyTotal() uint64_t DownloadThread::bytesWritten() { if (_sectorsStart != -1) - return (_sectorsWritten()-_sectorsStart)*512; + return qMin((uint64_t) (_sectorsWritten()-_sectorsStart)*512, (uint64_t) _bytesWritten); else return _bytesWritten; } @@ -619,7 +619,8 @@ bool DownloadThread::_verify() #ifdef Q_OS_LINUX /* Make sure we are reading from the drive and not from cache */ - fcntl(_file.handle(), F_SETFL, O_DIRECT | fcntl(_file.handle(), F_GETFL)); + //fcntl(_file.handle(), F_SETFL, O_DIRECT | fcntl(_file.handle(), F_GETFL)); + posix_fadvise(_file.handle(), 0, 0, POSIX_FADV_DONTNEED); #endif if (!_firstBlock)