[Pkg-owncloud-commits] [owncloud-client] 177/333: Detect the error that may happen when downloading a file

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Apr 17 23:16:50 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 05d3273591c197c24bb27a3a3efcd45da908e32e
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Wed Mar 19 15:19:09 2014 +0100

    Detect the error that may happen when downloading a file
---
 src/mirall/propagator_qnam.cpp | 24 +++++++++++++++++++++---
 src/mirall/propagator_qnam.h   |  6 ++++++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/mirall/propagator_qnam.cpp b/src/mirall/propagator_qnam.cpp
index 648e33f..fa4cc2b 100644
--- a/src/mirall/propagator_qnam.cpp
+++ b/src/mirall/propagator_qnam.cpp
@@ -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;
     }
 
diff --git a/src/mirall/propagator_qnam.h b/src/mirall/propagator_qnam.h
index f42bf07..0740a91 100644
--- a/src/mirall/propagator_qnam.h
+++ b/src/mirall/propagator_qnam.h
@@ -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);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list