mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 23:28:14 +03:00
Detect the error that may happen when downloading a file
This commit is contained in:
parent
39924d79cb
commit
05d3273591
2 changed files with 27 additions and 3 deletions
|
@ -296,8 +296,26 @@ void GETFileJob::start() {
|
|||
|
||||
void GETFileJob::slotReadyRead()
|
||||
{
|
||||
// FIXME: error handling (hard drive full, ....)
|
||||
_device->write(reply()->readAll());
|
||||
int bufferSize = qMax(1024*8ll , reply()->bytesAvailable());
|
||||
QByteArray buffer(bufferSize, Qt::Uninitialized);
|
||||
|
||||
while(reply()->bytesAvailable() > 0) {
|
||||
qint64 r = reply()->read(buffer.data(), bufferSize);
|
||||
if (r < 0) {
|
||||
_errorString = reply()->errorString();
|
||||
qDebug() << "Error while reading from device: " << _errorString;
|
||||
reply()->abort();
|
||||
return;
|
||||
}
|
||||
|
||||
qint64 w = _device->write(buffer.constData(), r);
|
||||
if (w != r) {
|
||||
_errorString = _device->errorString();
|
||||
qDebug() << "Error while writing to file" << w << r << _errorString;
|
||||
reply()->abort();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -395,7 +413,7 @@ void PropagateDownloadFileQNAM::slotGetFinished()
|
|||
}
|
||||
_item._httpErrorCode = job->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
_propagator->_activeJobs--;
|
||||
done(classifyError(err, _item._httpErrorCode), job->reply()->errorString());
|
||||
done(classifyError(err, _item._httpErrorCode), job->errorString());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,9 @@ class GETFileJob : public AbstractNetworkJob {
|
|||
Q_OBJECT
|
||||
QIODevice* _device;
|
||||
QMap<QByteArray, QByteArray> _headers;
|
||||
QString _errorString;
|
||||
public:
|
||||
|
||||
// DOES NOT take owncership of the device.
|
||||
explicit GETFileJob(Account* account, const QString& path, QIODevice *device,
|
||||
const QMap<QByteArray, QByteArray> &headers, QObject* parent = 0)
|
||||
|
@ -108,6 +110,10 @@ public:
|
|||
emit finishedSignal();
|
||||
}
|
||||
|
||||
QString errorString() {
|
||||
return _errorString.isEmpty() ? reply()->errorString() : _errorString;
|
||||
};
|
||||
|
||||
signals:
|
||||
void finishedSignal();
|
||||
void downloadProgress(qint64,qint64);
|
||||
|
|
Loading…
Reference in a new issue