Propagator: When the server don't support ranges, reset the counter so the progress is not messed up

Issue #2081
This commit is contained in:
Olivier Goffart 2014-08-29 19:23:08 +02:00
parent 1b51a10b19
commit 5d19426930
2 changed files with 9 additions and 6 deletions

View file

@ -484,7 +484,7 @@ void GETFileJob::slotMetaDataChanged()
}
quint64 start = 0;
QByteArray ranges = parseEtag(reply()->rawHeader("Content-Range"));
QByteArray ranges = reply()->rawHeader("Content-Range");
if (!ranges.isEmpty()) {
QRegExp rx("bytes (\\d+)-");
if (rx.indexIn(ranges) >= 0) {
@ -502,6 +502,7 @@ void GETFileJob::slotMetaDataChanged()
reply()->abort();
return;
}
_resumeStart = 0;
} else {
_errorString = tr("Server returned wrong content-range");
_errorStatus = SyncFileItem::NormalError;
@ -606,6 +607,7 @@ void PropagateDownloadFileQNAM::start()
QMap<QByteArray, QByteArray> headers;
quint64 startSize = 0;
if (_tmpFile.size() > 0) {
quint64 done = _tmpFile.size();
if (done == _item._size) {
@ -616,14 +618,14 @@ void PropagateDownloadFileQNAM::start()
headers["Range"] = "bytes=" + QByteArray::number(done) +'-';
headers["Accept-Ranges"] = "bytes";
qDebug() << "Retry with range " << headers["Range"];
_startSize = done;
startSize = done;
}
if (_item._directDownloadUrl.isEmpty()) {
// Normal job, download from oC instance
_job = new GETFileJob(AccountManager::instance()->account(),
_propagator->_remoteFolder + _item._file,
&_tmpFile, headers, expectedEtagForResume, _startSize);
&_tmpFile, headers, expectedEtagForResume, startSize);
} else {
// We were provided a direct URL, use that one
if (!_item._directDownloadCookies.isEmpty()) {
@ -748,7 +750,8 @@ void PropagateDownloadFileQNAM::downloadFinished()
void PropagateDownloadFileQNAM::slotDownloadProgress(qint64 received, qint64)
{
emit progress(_item, received + _startSize);
if (!_job) return;
emit progress(_item, received + _job->resumeStart());
}

View file

@ -139,6 +139,7 @@ public:
virtual void slotTimeout() Q_DECL_OVERRIDE;
QByteArray &etag() { return _etag; }
quint64 resumeStart() { return _resumeStart; }
signals:
@ -156,10 +157,9 @@ class PropagateDownloadFileQNAM : public PropagateItemJob {
// QFile *_file;
QFile _tmpFile;
quint64 _startSize;
public:
PropagateDownloadFileQNAM(OwncloudPropagator* propagator,const SyncFileItem& item)
: PropagateItemJob(propagator, item), _startSize(0) {}
: PropagateItemJob(propagator, item) {}
void start() Q_DECL_OVERRIDE;
private slots:
void slotGetFinished();