[Pkg-owncloud-commits] [owncloud-client] 182/333: QNAM jobs: Make sure there is an etag is proper and not changed when one resume

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 ebeb668a621b7c800324549d3c9d9a64ef20ab05
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Thu Mar 20 13:26:40 2014 +0100

    QNAM jobs: Make sure there is an etag is proper and not changed when one resume
    
    Those tests are existing on the legacy jobs.
    
    We check there is an etag so we make sure a proxy is not in between.
    (We have seen user complaining because their proxy is replacing the
    pages with one that says they need to enter their login and password)
    
    Also it is important to check that the etag has not changed if we resume
    (this may happen if the file is changed on the server between the update
    phase and the propagate phase,  and that we resume this file)
---
 src/mirall/propagator_qnam.cpp | 27 +++++++++++++++++++++++++--
 src/mirall/propagator_qnam.h   |  9 ++++++---
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/src/mirall/propagator_qnam.cpp b/src/mirall/propagator_qnam.cpp
index fa4cc2b..280382e 100644
--- a/src/mirall/propagator_qnam.cpp
+++ b/src/mirall/propagator_qnam.cpp
@@ -288,12 +288,31 @@ void GETFileJob::start() {
         qWarning() << Q_FUNC_INFO << " Network error: " << reply()->errorString();
     }
 
+    connect(reply(), SIGNAL(metaDataChanged()), this, SLOT(slotMetaDataChanged()));
     connect(reply(), SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
     connect(reply(), SIGNAL(downloadProgress(qint64,qint64)), this, SIGNAL(downloadProgress(qint64,qint64)));
 
     AbstractNetworkJob::start();
 }
 
+void GETFileJob::slotMetaDataChanged()
+{
+    QByteArray etag = parseEtag(reply()->rawHeader("Etag"));
+
+    if (etag.isEmpty()) {
+        qDebug() << Q_FUNC_INFO << "No E-Tag reply by server, considering it invalid";
+        _errorString = tr("No E-Tag received from server, check Proxy/Gateway");
+        reply()->abort();
+        return;
+    } else if (!_expectedEtagForResume.isEmpty() && _expectedEtagForResume != etag) {
+        qDebug() << Q_FUNC_INFO <<  "We received a different E-Tag for resuming!"
+                << _expectedEtagForResume << "vs" << etag;
+        _errorString = tr("We received a different E-Tag for resuming. Retrying next time.");
+        reply()->abort();
+        return;
+    }
+}
+
 void GETFileJob::slotReadyRead()
 {
     int bufferSize = qMax(1024*8ll , reply()->bytesAvailable());
@@ -319,6 +338,7 @@ void GETFileJob::slotReadyRead()
 }
 
 
+
 void PropagateDownloadFileQNAM::start()
 {
     if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
@@ -329,6 +349,7 @@ void PropagateDownloadFileQNAM::start()
     emit progress(_item, 0);
 
     QString tmpFileName;
+    QByteArray expectedEtagForResume;
     const SyncJournalDb::DownloadInfo progressInfo = _propagator->_journal->getDownloadInfo(_item._file);
     if (progressInfo._valid) {
         // if the etag has changed meanwhile, remove the already downloaded part.
@@ -337,7 +358,7 @@ void PropagateDownloadFileQNAM::start()
             _propagator->_journal->setDownloadInfo(_item._file, SyncJournalDb::DownloadInfo());
         } else {
             tmpFileName = progressInfo._tmpfile;
-            _expectedEtagForResume = progressInfo._etag;
+            expectedEtagForResume = progressInfo._etag;
         }
 
     }
@@ -386,7 +407,9 @@ void PropagateDownloadFileQNAM::start()
         _startSize = done;
     }
 
-    _job = new GETFileJob(AccountManager::instance()->account(), _propagator->_remoteFolder + _item._file, &_tmpFile, headers);
+    _job = new GETFileJob(AccountManager::instance()->account(),
+                          _propagator->_remoteFolder + _item._file,
+                          &_tmpFile, headers, expectedEtagForResume);
     connect(_job, SIGNAL(finishedSignal()), this, SLOT(slotGetFinished()));
     connect(_job, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(slotDownloadProgress(qint64,qint64)));
     _propagator->_activeJobs ++;
diff --git a/src/mirall/propagator_qnam.h b/src/mirall/propagator_qnam.h
index 0740a91..ca76c22 100644
--- a/src/mirall/propagator_qnam.h
+++ b/src/mirall/propagator_qnam.h
@@ -98,12 +98,15 @@ class GETFileJob : public AbstractNetworkJob {
     QIODevice* _device;
     QMap<QByteArray, QByteArray> _headers;
     QString _errorString;
+    QByteArray _expectedEtagForResume;
 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)
-    : AbstractNetworkJob(account, path, parent), _device(device), _headers(headers) {}
+                        const QMap<QByteArray, QByteArray> &headers, QByteArray expectedEtagForResume,
+                        QObject* parent = 0)
+    : AbstractNetworkJob(account, path, parent),
+      _device(device), _headers(headers), _expectedEtagForResume(expectedEtagForResume) {}
 
     virtual void start();
     virtual void finished() {
@@ -119,13 +122,13 @@ signals:
     void downloadProgress(qint64,qint64);
 private slots:
     void slotReadyRead();
+    void slotMetaDataChanged();
 };
 
 
 class PropagateDownloadFileQNAM : public PropagateItemJob {
     Q_OBJECT
     QPointer<GETFileJob> _job;
-    QByteArray _expectedEtagForResume;
 
 //  QFile *_file;
     QFile _tmpFile;

-- 
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