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
This commit is contained in:
Floris Bos 2020-06-30 00:13:46 +02:00
parent a7a2501047
commit 83ae3f1cbd

View file

@ -515,7 +515,7 @@ uint64_t DownloadThread::verifyTotal()
uint64_t DownloadThread::bytesWritten() uint64_t DownloadThread::bytesWritten()
{ {
if (_sectorsStart != -1) if (_sectorsStart != -1)
return (_sectorsWritten()-_sectorsStart)*512; return qMin((uint64_t) (_sectorsWritten()-_sectorsStart)*512, (uint64_t) _bytesWritten);
else else
return _bytesWritten; return _bytesWritten;
} }
@ -619,7 +619,8 @@ bool DownloadThread::_verify()
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
/* Make sure we are reading from the drive and not from cache */ /* 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 #endif
if (!_firstBlock) if (!_firstBlock)