Linux: improve progess indication

Report data actually written to device instead of to cache.
This commit is contained in:
Floris Bos 2020-05-23 22:22:32 +02:00
parent b08ed20e5f
commit 3248f9f04b
2 changed files with 28 additions and 3 deletions

View file

@ -32,7 +32,7 @@ QByteArray DownloadThread::_proxy;
int DownloadThread::_curlCount = 0; int DownloadThread::_curlCount = 0;
DownloadThread::DownloadThread(const QByteArray &url, const QByteArray &localfilename, const QByteArray &expectedHash, QObject *parent) : DownloadThread::DownloadThread(const QByteArray &url, const QByteArray &localfilename, const QByteArray &expectedHash, QObject *parent) :
QThread(parent), _startOffset(0), _lastDlTotal(0), _lastDlNow(0), _verifyTotal(0), _lastVerifyNow(0), _bytesWritten(0), _url(url), _filename(localfilename), _expectedHash(expectedHash), QThread(parent), _startOffset(0), _lastDlTotal(0), _lastDlNow(0), _verifyTotal(0), _lastVerifyNow(0), _bytesWritten(0), _sectorsStart(-1), _url(url), _filename(localfilename), _expectedHash(expectedHash),
_firstBlock(nullptr), _cancelled(false), _successful(false), _verifyEnabled(false), _cacheEnabled(false), _lastModified(0), _serverTime(0), _lastFailureTime(0), _firstBlock(nullptr), _cancelled(false), _successful(false), _verifyEnabled(false), _cacheEnabled(false), _lastModified(0), _serverTime(0), _lastFailureTime(0),
_file(NULL), _writehash(OSLIST_HASH_ALGORITHM), _verifyhash(OSLIST_HASH_ALGORITHM), _inputBufferSize(0) _file(NULL), _writehash(OSLIST_HASH_ALGORITHM), _verifyhash(OSLIST_HASH_ALGORITHM), _inputBufferSize(0)
{ {
@ -253,6 +253,7 @@ bool DownloadThread::_openAndPrepareDevice()
qDebug() << "BLKDISCARD successful"; qDebug() << "BLKDISCARD successful";
} }
} }
_sectorsStart = _sectorsWritten();
#endif #endif
return true; return true;
@ -288,7 +289,6 @@ void DownloadThread::run()
if (!_proxy.isEmpty()) if (!_proxy.isEmpty())
curl_easy_setopt(_c, CURLOPT_PROXY, _proxy.constData()); curl_easy_setopt(_c, CURLOPT_PROXY, _proxy.constData());
_timer.start(); _timer.start();
CURLcode ret = curl_easy_perform(_c); CURLcode ret = curl_easy_perform(_c);
@ -503,6 +503,9 @@ uint64_t DownloadThread::verifyTotal()
uint64_t DownloadThread::bytesWritten() uint64_t DownloadThread::bytesWritten()
{ {
if (_sectorsStart != -1)
return (_sectorsWritten()-_sectorsStart)*512;
else
return _bytesWritten; return _bytesWritten;
} }
@ -663,3 +666,23 @@ void DownloadThread::setInputBufferSize(int len)
{ {
_inputBufferSize = len; _inputBufferSize = len;
} }
qint64 DownloadThread::_sectorsWritten()
{
#ifdef Q_OS_LINUX
if (!_filename.startsWith("/dev/"))
return -1;
QFile f("/sys/class/block/"+_filename.mid(5)+"/stat");
if (!f.open(f.ReadOnly))
return -1;
QByteArray ioline = f.readAll().simplified();
f.close();
QList<QByteArray> stats = ioline.split(' ');
if (stats.count() >= 6)
return stats.at(6).toLongLong(); /* write sectors */
#endif
return -1;
}

View file

@ -138,6 +138,7 @@ protected:
int _authopen(const QByteArray &filename); int _authopen(const QByteArray &filename);
bool _openAndPrepareDevice(); bool _openAndPrepareDevice();
void _writeCache(const char *buf, size_t len); void _writeCache(const char *buf, size_t len);
qint64 _sectorsWritten();
/* /*
* libcurl callbacks * libcurl callbacks
@ -153,6 +154,7 @@ protected:
CURL *_c; CURL *_c;
curl_off_t _startOffset; curl_off_t _startOffset;
std::atomic<std::uint64_t> _lastDlTotal, _lastDlNow, _verifyTotal, _lastVerifyNow, _bytesWritten; std::atomic<std::uint64_t> _lastDlTotal, _lastDlNow, _verifyTotal, _lastVerifyNow, _bytesWritten;
qint64 _sectorsStart;
QByteArray _url, _useragent, _buf, _filename, _lastError, _expectedHash; QByteArray _url, _useragent, _buf, _filename, _lastError, _expectedHash;
char *_firstBlock; char *_firstBlock;
size_t _firstBlockSize; size_t _firstBlockSize;