[Pkg-owncloud-commits] [owncloud-client] 181/484: Checksum: Put checksum type into separate column #3735

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Dec 16 00:37:40 UTC 2015


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 b7823dc648f22ee0aa33f6d918b24341b0954acf
Author: Christian Kamm <mail at ckamm.de>
Date:   Wed Oct 28 11:00:03 2015 +0100

    Checksum: Put checksum type into separate column #3735
---
 src/libsync/ownsql.cpp                        |   5 ++
 src/libsync/ownsql.h                          |   3 +
 src/libsync/propagatedownload.cpp             |  17 ++--
 src/libsync/propagatedownload.h               |   2 +-
 src/libsync/propagateupload.cpp               |  35 +++++----
 src/libsync/syncfileitem.h                    |   3 +-
 src/libsync/syncjournaldb.cpp                 | 108 +++++++++++++++++++++-----
 src/libsync/syncjournaldb.h                   |  13 +++-
 src/libsync/syncjournalfilerecord.cpp         |   8 +-
 src/libsync/syncjournalfilerecord.h           |   3 +-
 src/libsync/transmissionchecksumvalidator.cpp |   4 +-
 src/libsync/transmissionchecksumvalidator.h   |   2 +-
 test/testsyncjournaldb.h                      |  27 +++++++
 test/testtranschecksumvalidator.h             |   2 +-
 14 files changed, 179 insertions(+), 53 deletions(-)

diff --git a/src/libsync/ownsql.cpp b/src/libsync/ownsql.cpp
index 9245c86..0f2c592 100644
--- a/src/libsync/ownsql.cpp
+++ b/src/libsync/ownsql.cpp
@@ -316,6 +316,11 @@ void SqlQuery::bindValue(int pos, const QVariant& value)
     Q_ASSERT( res == SQLITE_OK );
 }
 
+bool SqlQuery::nullValue(int index)
+{
+    return sqlite3_column_type(_stmt, index) == SQLITE_NULL;
+}
+
 QString SqlQuery::stringValue(int index)
 {
     return QString::fromUtf16(static_cast<const ushort*>(sqlite3_column_text16(_stmt, index)));
diff --git a/src/libsync/ownsql.h b/src/libsync/ownsql.h
index bcff7f5..3da2e75 100644
--- a/src/libsync/ownsql.h
+++ b/src/libsync/ownsql.h
@@ -66,6 +66,9 @@ public:
     ~SqlQuery();
     QString error() const;
 
+    /// Checks whether the value at the given column index is NULL
+    bool nullValue(int index);
+
     QString stringValue(int index);
     int intValue(int index);
     quint64 int64Value(int index);
diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp
index 1f0a1b7..3636d2c 100644
--- a/src/libsync/propagatedownload.cpp
+++ b/src/libsync/propagatedownload.cpp
@@ -353,8 +353,8 @@ void PropagateDownloadFileQNAM::start()
             _tmpFile.close();
 
             // Unfortunately we lost the checksum header, if any...
-            QByteArray checksumHeader;
-            downloadFinished(checksumHeader);
+            QByteArray noChecksumData;
+            downloadFinished(noChecksumData, noChecksumData);
             return;
         }
     }
@@ -535,8 +535,10 @@ void PropagateDownloadFileQNAM::slotGetFinished()
     // will also emit the validated() signal to continue the flow in slot downloadFinished()
     // as this is (still) also correct.
     ValidateChecksumHeader *validator = new ValidateChecksumHeader(this);
-    connect(validator, SIGNAL(validated(QByteArray)), this, SLOT(downloadFinished(QByteArray)));
-    connect(validator, SIGNAL(validationFailed(QString)), this, SLOT(slotChecksumFail(QString)));
+    connect(validator, SIGNAL(validated(QByteArray,QByteArray)),
+            SLOT(downloadFinished(QByteArray,QByteArray)));
+    connect(validator, SIGNAL(validationFailed(QString)),
+            SLOT(slotChecksumFail(QString)));
     auto checksumHeader = job->reply()->rawHeader(checkSumHeaderC);
     if (!downloadChecksumEnabled()) {
         checksumHeader.clear();
@@ -618,10 +620,11 @@ static void handleRecallFile(const QString &fn)
 }
 } // end namespace
 
-void PropagateDownloadFileQNAM::downloadFinished(const QByteArray& checksumHeader)
+void PropagateDownloadFileQNAM::downloadFinished(const QByteArray& checksumType, const QByteArray& checksum)
 {
-    if (!checksumHeader.isEmpty()) {
-        _item->_checksumHeader = checksumHeader;
+    if (!checksumType.isEmpty()) {
+        _item->_transmissionChecksum = checksum;
+        _item->_transmissionChecksumType = checksumType;
     }
 
     QString fn = _propagator->getFilePath(_item->_file);
diff --git a/src/libsync/propagatedownload.h b/src/libsync/propagatedownload.h
index 9a5c2b3..2a8877e 100644
--- a/src/libsync/propagatedownload.h
+++ b/src/libsync/propagatedownload.h
@@ -117,7 +117,7 @@ public:
 private slots:
     void slotGetFinished();
     void abort() Q_DECL_OVERRIDE;
-    void downloadFinished(const QByteArray& checksumHeader);
+    void downloadFinished(const QByteArray& checksumType, const QByteArray& checksum);
     void slotDownloadProgress(qint64,qint64);
     void slotChecksumFail( const QString& errMsg );
 
diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp
index 3412c0e..10724a4 100644
--- a/src/libsync/propagateupload.cpp
+++ b/src/libsync/propagateupload.cpp
@@ -213,14 +213,11 @@ void PropagateUploadFileQNAM::start()
 
     // If we already have a checksum header and the checksum type is supported
     // by the server, we keep that - otherwise recompute.
-    if (!_item->_checksumHeader.isEmpty()) {
-        QByteArray checksumType;
-        QByteArray checksum;
-        if (parseChecksumHeader(_item->_checksumHeader, &checksumType, &checksum)
-                && supportedChecksumTypes.contains(checksumType)) {
+    if (!_item->_transmissionChecksumType.isEmpty()) {
+        if (supportedChecksumTypes.contains(_item->_transmissionChecksumType)) {
             // TODO: We could validate the old checksum and thereby determine whether
             // an upload is necessary or not.
-            slotStartUpload(checksumType, checksum);
+            slotStartUpload(_item->_transmissionChecksumType, _item->_transmissionChecksum);
             return;
         }
     }
@@ -241,10 +238,12 @@ void PropagateUploadFileQNAM::start()
 void PropagateUploadFileQNAM::slotStartUpload(const QByteArray& checksumType, const QByteArray& checksum)
 {
     // Store the computed checksum in the database, if different
-    auto newChecksumHeader = makeChecksumHeader(checksumType, checksum);
-    if (newChecksumHeader != _item->_checksumHeader) {
-        _item->_checksumHeader = newChecksumHeader;
-        _propagator->_journal->updateFileRecordChecksumHeader(_item->_file, _item->_checksumHeader);
+    if (checksumType != _item->_transmissionChecksumType
+            || checksum != _item->_transmissionChecksum) {
+        _item->_transmissionChecksum = checksum;
+        _item->_transmissionChecksumType = checksumType;
+        _propagator->_journal->updateFileRecordChecksumHeader(
+                _item->_file, checksum, checksumType);
     }
 
     const QString fullFilePath = _propagator->getFilePath(_item->_file);
@@ -477,6 +476,7 @@ void PropagateUploadFileQNAM::startNextChunk()
     UploadDevice *device = new UploadDevice(&_propagator->_bandwidthManager);
     qint64 chunkStart = 0;
     qint64 currentChunkSize = fileSize;
+    bool isFinalChunk = false;
     if (_chunkCount > 1) {
         int sendingChunk = (_currentChunk + _startChunk) % _chunkCount;
         // XOR with chunk size to make sure everything goes well if chunk size changes between runs
@@ -493,15 +493,16 @@ void PropagateUploadFileQNAM::startNextChunk()
             if( currentChunkSize == 0 ) { // if the last chunk pretends to be 0, its actually the full chunk size.
                 currentChunkSize = chunkSize();
             }
-            if( !_item->_checksumHeader.isEmpty() ) {
-                headers[checkSumHeaderC] = _item->_checksumHeader;
-            }
+            isFinalChunk = true;
         }
     } else {
-        // checksum if its only one chunk
-        if( !_item->_checksumHeader.isEmpty() ) {
-            headers[checkSumHeaderC] = _item->_checksumHeader;
-        }
+        // if there's only one chunk, it's the final one
+        isFinalChunk = true;
+    }
+
+    if (isFinalChunk && !_item->_transmissionChecksumType.isEmpty()) {
+        headers[checkSumHeaderC] = makeChecksumHeader(
+                _item->_transmissionChecksumType, _item->_transmissionChecksum);
     }
 
     if (! device->prepareAndOpen(_propagator->getFilePath(_item->_file), chunkStart, currentChunkSize)) {
diff --git a/src/libsync/syncfileitem.h b/src/libsync/syncfileitem.h
index b6a6558..0ded88e 100644
--- a/src/libsync/syncfileitem.h
+++ b/src/libsync/syncfileitem.h
@@ -157,7 +157,8 @@ public:
     quint64              _inode;
     QByteArray           _fileId;
     QByteArray           _remotePerm;
-    QByteArray           _checksumHeader;
+    QByteArray           _transmissionChecksum;
+    QByteArray           _transmissionChecksumType;
     QString              _directDownloadUrl;
     QString              _directDownloadCookies;
 
diff --git a/src/libsync/syncjournaldb.cpp b/src/libsync/syncjournaldb.cpp
index db1814e..67e2365 100644
--- a/src/libsync/syncjournaldb.cpp
+++ b/src/libsync/syncjournaldb.cpp
@@ -206,7 +206,8 @@ bool SyncJournalDb::checkConnect()
                          "md5 VARCHAR(32)," /* This is the etag.  Called md5 for compatibility */
                         // updateDatabaseStructure() will add a fileid column
                         // updateDatabaseStructure() will add a remotePerm column
-                        // updateDatabaseStructure() will add a checksumHeader column
+                        // updateDatabaseStructure() will add a transmissionChecksum column
+                        // updateDatabaseStructure() will add a transmissionChecksumTypeId column
                          "PRIMARY KEY(phash)"
                          ");");
 
@@ -272,6 +273,14 @@ bool SyncJournalDb::checkConnect()
         return sqlFail("Create table selectivesync", createQuery);
     }
 
+    // create the checksumtype table.
+    createQuery.prepare("CREATE TABLE IF NOT EXISTS checksumtype("
+                               "id INTEGER PRIMARY KEY,"
+                               "name TEXT UNIQUE"
+                               ");");
+    if (!createQuery.exec()) {
+        return sqlFail("Create table version", createQuery);
+    }
 
 
     createQuery.prepare("CREATE TABLE IF NOT EXISTS version("
@@ -347,16 +356,20 @@ bool SyncJournalDb::checkConnect()
     }
 
     _getFileRecordQuery.reset(new SqlQuery(_db));
-    _getFileRecordQuery->prepare("SELECT path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize, ignoredChildrenRemote, checksumHeader FROM "
-                                 "metadata WHERE phash=?1" );
+    _getFileRecordQuery->prepare(
+            "SELECT path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize,"
+            "  ignoredChildrenRemote, transmissionChecksum, checksumtype.name"
+            " FROM metadata"
+            "  LEFT JOIN checksumtype ON metadata.transmissionChecksumTypeId == checksumtype.id"
+            " WHERE phash=?1" );
 
     _setFileRecordQuery.reset(new SqlQuery(_db) );
     _setFileRecordQuery->prepare("INSERT OR REPLACE INTO metadata "
-                                 "(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize, ignoredChildrenRemote, checksumHeader) "
-                                 "VALUES (?1 , ?2, ?3 , ?4 , ?5 , ?6 , ?7,  ?8 , ?9 , ?10, ?11, ?12, ?13, ?14, ?15);" );
+                                 "(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize, ignoredChildrenRemote, transmissionChecksum, transmissionChecksumTypeId) "
+                                 "VALUES (?1 , ?2, ?3 , ?4 , ?5 , ?6 , ?7,  ?8 , ?9 , ?10, ?11, ?12, ?13, ?14, ?15, ?16);" );
 
-    _setFileRecordChecksumHeaderQuery.reset(new SqlQuery(_db) );
-    _setFileRecordChecksumHeaderQuery->prepare("UPDATE metadata SET checksumHeader = ?2 WHERE phash == ?1;");
+    _setFileRecordChecksumQuery.reset(new SqlQuery(_db) );
+    _setFileRecordChecksumQuery->prepare("UPDATE metadata SET transmissionChecksum = ?2, transmissionChecksumTypeId = ?3 WHERE phash == ?1;");
 
     _getDownloadInfoQuery.reset(new SqlQuery(_db) );
     _getDownloadInfoQuery->prepare( "SELECT tmpfile, etag, errorcount FROM "
@@ -407,6 +420,12 @@ bool SyncJournalDb::checkConnect()
     _getSelectiveSyncListQuery.reset(new SqlQuery(_db));
     _getSelectiveSyncListQuery->prepare("SELECT path FROM selectivesync WHERE type=?1");
 
+    _getChecksumTypeIdQuery.reset(new SqlQuery(_db));
+    _getChecksumTypeIdQuery->prepare("SELECT id FROM checksumtype WHERE name=?1");
+
+    _insertChecksumTypeQuery.reset(new SqlQuery(_db));
+    _insertChecksumTypeQuery->prepare("INSERT OR IGNORE INTO checksumtype (name) VALUES (?1)");
+
     // don't start a new transaction now
     commitInternal(QString("checkConnect End"), false);
 
@@ -532,16 +551,26 @@ bool SyncJournalDb::updateMetadataTableStructure()
         commitInternal("update database structure: add ignoredChildrenRemote col");
     }
 
-    if( columns.indexOf(QLatin1String("checksumHeader")) == -1 ) {
+    if( columns.indexOf(QLatin1String("transmissionChecksum")) == -1 ) {
+        SqlQuery query(_db);
+        query.prepare("ALTER TABLE metadata ADD COLUMN transmissionChecksum TEXT;");
+        if( !query.exec()) {
+            sqlFail("updateMetadataTableStructure: add transmissionChecksum column", query);
+            re = false;
+        }
+        commitInternal("update database structure: add transmissionChecksum col");
+    }
+    if( columns.indexOf(QLatin1String("transmissionChecksumTypeId")) == -1 ) {
         SqlQuery query(_db);
-        query.prepare("ALTER TABLE metadata ADD COLUMN checksumHeader TEXT;");
+        query.prepare("ALTER TABLE metadata ADD COLUMN transmissionChecksumTypeId INTEGER;");
         if( !query.exec()) {
-            sqlFail("updateMetadataTableStructure: add checksumHeader column", query);
+            sqlFail("updateMetadataTableStructure: add transmissionChecksumTypeId column", query);
             re = false;
         }
-        commitInternal("update database structure: add checksumHeader col");
+        commitInternal("update database structure: add transmissionChecksumTypeId col");
     }
 
+
     return re;
 }
 
@@ -642,6 +671,7 @@ bool SyncJournalDb::setFileRecord( const SyncJournalFileRecord& _record )
         if( fileId.isEmpty() ) fileId = "";
         QString remotePerm (record._remotePerm);
         if (remotePerm.isEmpty()) remotePerm = QString(); // have NULL in DB (vs empty)
+        int checksumTypeId = mapChecksumType(record._transmissionChecksumType);
         _setFileRecordQuery->reset();
         _setFileRecordQuery->bindValue(1, QString::number(phash));
         _setFileRecordQuery->bindValue(2, plen);
@@ -657,7 +687,8 @@ bool SyncJournalDb::setFileRecord( const SyncJournalFileRecord& _record )
         _setFileRecordQuery->bindValue(12, remotePerm );
         _setFileRecordQuery->bindValue(13, record._fileSize );
         _setFileRecordQuery->bindValue(14, record._serverHasIgnoredFiles ? 1:0);
-        _setFileRecordQuery->bindValue(15, record._checksumHeader );
+        _setFileRecordQuery->bindValue(15, record._transmissionChecksum );
+        _setFileRecordQuery->bindValue(16, checksumTypeId );
 
         if( !_setFileRecordQuery->exec() ) {
             qWarning() << "Error SQL statement setFileRecord: " << _setFileRecordQuery->lastQuery() <<  " :"
@@ -669,7 +700,7 @@ bool SyncJournalDb::setFileRecord( const SyncJournalFileRecord& _record )
                  << record._mode
                  << QString::number(Utility::qDateTimeToTime_t(record._modtime)) << QString::number(record._type)
                  << record._etag << record._fileId << record._remotePerm << record._fileSize << (record._serverHasIgnoredFiles ? 1:0)
-                 << record._checksumHeader;
+                 << record._transmissionChecksum << record._transmissionChecksumType << checksumTypeId;
 
         _setFileRecordQuery->reset();
         return true;
@@ -749,7 +780,10 @@ SyncJournalFileRecord SyncJournalDb::getFileRecord( const QString& filename )
             rec._remotePerm = _getFileRecordQuery->baValue(9);
             rec._fileSize   = _getFileRecordQuery->int64Value(10);
             rec._serverHasIgnoredFiles = (_getFileRecordQuery->intValue(11) > 0);
-            rec._checksumHeader = _getFileRecordQuery->baValue(12);
+            rec._transmissionChecksum = _getFileRecordQuery->baValue(12);
+            if( !_getFileRecordQuery->nullValue(13) ) {
+                rec._transmissionChecksumType = _getFileRecordQuery->baValue(13);
+            }
         } else {
             QString err = _getFileRecordQuery->error();
             qDebug() << "No journal entry found for " << filename;
@@ -838,7 +872,9 @@ int SyncJournalDb::getFileRecordCount()
     return 0;
 }
 
-bool SyncJournalDb::updateFileRecordChecksumHeader(const QString &filename, const QByteArray &checksumHeader)
+bool SyncJournalDb::updateFileRecordChecksumHeader(const QString& filename,
+                                                   const QByteArray& transmisisonChecksum,
+                                                   const QByteArray& transmissionChecksumType)
 {
     QMutexLocker locker(&_mutex);
 
@@ -848,11 +884,13 @@ bool SyncJournalDb::updateFileRecordChecksumHeader(const QString &filename, cons
         return false;
     }
 
-    auto & query = _setFileRecordChecksumHeaderQuery;
+    int checksumTypeId = mapChecksumType(transmissionChecksumType);
+    auto & query = _setFileRecordChecksumQuery;
 
     query->reset();
     query->bindValue(1, QString::number(phash));
-    query->bindValue(2, checksumHeader);
+    query->bindValue(2, transmisisonChecksum);
+    query->bindValue(3, checksumTypeId);
 
     if( !query->exec() ) {
         qWarning() << "Error SQL statement setFileRecordChecksumHeaderQuery: "
@@ -861,7 +899,8 @@ bool SyncJournalDb::updateFileRecordChecksumHeader(const QString &filename, cons
         return false;
     }
 
-    qDebug() << query->lastQuery() << phash << checksumHeader;
+    qDebug() << query->lastQuery() << phash << transmisisonChecksum
+             << transmissionChecksumType << checksumTypeId;
 
     query->reset();
     return true;
@@ -1436,6 +1475,39 @@ void SyncJournalDb::forceRemoteDiscoveryNextSyncLocked()
     }
 }
 
+int SyncJournalDb::mapChecksumType(const QByteArray& checksumType)
+{
+    if (checksumType.isEmpty()) {
+        return 0;
+    }
+
+    // Ensure the checksum type is in the db
+    _insertChecksumTypeQuery->reset();
+    _insertChecksumTypeQuery->bindValue(1, checksumType);
+    if( !_insertChecksumTypeQuery->exec() ) {
+        qWarning() << "Error SQL statement insertChecksumType: "
+                   << _insertChecksumTypeQuery->lastQuery() <<  " :"
+                   << _insertChecksumTypeQuery->error();
+        return 0;
+    }
+
+    // Retrieve the id
+    _getChecksumTypeIdQuery->reset();
+    _getChecksumTypeIdQuery->bindValue(1, checksumType);
+    if( !_getChecksumTypeIdQuery->exec() ) {
+        qWarning() << "Error SQL statement getChecksumTypeId: "
+                   << _getChecksumTypeIdQuery->lastQuery() <<  " :"
+                   << _getChecksumTypeIdQuery->error();
+        return 0;
+    }
+
+    if( !_getChecksumTypeIdQuery->next() ) {
+        qDebug() << "No checksum type mapping found for" << checksumType;
+        return 0;
+    }
+    return _getChecksumTypeIdQuery->intValue(0);
+}
+
 
 void SyncJournalDb::commit(const QString& context, bool startTrans)
 {
diff --git a/src/libsync/syncjournaldb.h b/src/libsync/syncjournaldb.h
index 226fa31..775c9f4 100644
--- a/src/libsync/syncjournaldb.h
+++ b/src/libsync/syncjournaldb.h
@@ -42,7 +42,9 @@ public:
     bool setFileRecord( const SyncJournalFileRecord& record );
     bool deleteFileRecord( const QString& filename, bool recursively = false );
     int getFileRecordCount();
-    bool updateFileRecordChecksumHeader(const QString& filename, const QByteArray& checksumHeader);
+    bool updateFileRecordChecksumHeader(const QString& filename,
+                                        const QByteArray& transmisisonChecksum,
+                                        const QByteArray& transmissionChecksumType);
     bool exists();
     void walCheckpoint();
 
@@ -154,13 +156,18 @@ private:
     // Same as forceRemoteDiscoveryNextSync but without acquiring the lock
     void forceRemoteDiscoveryNextSyncLocked();
 
+    // Returns the integer id of the checksum type
+    //
+    // Returns 0 on failure and for empty checksum types.
+    int mapChecksumType(const QByteArray& checksumType);
+
     SqlDatabase _db;
     QString _dbFile;
     QMutex _mutex; // Public functions are protected with the mutex.
     int _transaction;
     QScopedPointer<SqlQuery> _getFileRecordQuery;
     QScopedPointer<SqlQuery> _setFileRecordQuery;
-    QScopedPointer<SqlQuery> _setFileRecordChecksumHeaderQuery;
+    QScopedPointer<SqlQuery> _setFileRecordChecksumQuery;
     QScopedPointer<SqlQuery> _getDownloadInfoQuery;
     QScopedPointer<SqlQuery> _setDownloadInfoQuery;
     QScopedPointer<SqlQuery> _deleteDownloadInfoQuery;
@@ -172,6 +179,8 @@ private:
     QScopedPointer<SqlQuery> _getErrorBlacklistQuery;
     QScopedPointer<SqlQuery> _setErrorBlacklistQuery;
     QScopedPointer<SqlQuery> _getSelectiveSyncListQuery;
+    QScopedPointer<SqlQuery> _getChecksumTypeIdQuery;
+    QScopedPointer<SqlQuery> _insertChecksumTypeQuery;
 
     /* This is the list of paths we called avoidReadFromDbOnNextSync on.
      * It means that they should not be written to the DB in any case since doing
diff --git a/src/libsync/syncjournalfilerecord.cpp b/src/libsync/syncjournalfilerecord.cpp
index 22ee38b..8c03f77 100644
--- a/src/libsync/syncjournalfilerecord.cpp
+++ b/src/libsync/syncjournalfilerecord.cpp
@@ -36,7 +36,8 @@ SyncJournalFileRecord::SyncJournalFileRecord(const SyncFileItem &item, const QSt
     : _path(item._file), _modtime(Utility::qDateTimeFromTime_t(item._modtime)),
       _type(item._type), _etag(item._etag), _fileId(item._fileId), _fileSize(item._size),
       _remotePerm(item._remotePerm), _mode(0), _serverHasIgnoredFiles(item._serverHasIgnoredFiles),
-      _checksumHeader(item._checksumHeader)
+      _transmissionChecksum(item._transmissionChecksum),
+      _transmissionChecksumType(item._transmissionChecksumType)
 {
     // use the "old" inode coming with the item for the case where the
     // filesystem stat fails. That can happen if the the file was removed
@@ -151,9 +152,12 @@ bool operator==(const SyncJournalFileRecord & lhs,
             && lhs._type == rhs._type
             && lhs._etag == rhs._etag
             && lhs._fileId == rhs._fileId
+            && lhs._fileSize == rhs._fileSize
             && lhs._remotePerm == rhs._remotePerm
             && lhs._mode == rhs._mode
-            && lhs._fileSize == rhs._fileSize;
+            && lhs._serverHasIgnoredFiles == rhs._serverHasIgnoredFiles
+            && lhs._transmissionChecksum == rhs._transmissionChecksum
+            && lhs._transmissionChecksumType == rhs._transmissionChecksumType;
 }
 
 }
diff --git a/src/libsync/syncjournalfilerecord.h b/src/libsync/syncjournalfilerecord.h
index d3a2a70..4165caf 100644
--- a/src/libsync/syncjournalfilerecord.h
+++ b/src/libsync/syncjournalfilerecord.h
@@ -47,7 +47,8 @@ public:
     QByteArray _remotePerm;
     int        _mode;
     bool       _serverHasIgnoredFiles;
-    QByteArray _checksumHeader;
+    QByteArray _transmissionChecksum;
+    QByteArray _transmissionChecksumType;
 };
 
 bool OWNCLOUDSYNC_EXPORT
diff --git a/src/libsync/transmissionchecksumvalidator.cpp b/src/libsync/transmissionchecksumvalidator.cpp
index 1a0caaf..15923bd 100644
--- a/src/libsync/transmissionchecksumvalidator.cpp
+++ b/src/libsync/transmissionchecksumvalidator.cpp
@@ -119,7 +119,7 @@ void ValidateChecksumHeader::start(const QString& filePath, const QByteArray& ch
 {
     // If the incoming header is empty no validation can happen. Just continue.
     if( checksumHeader.isEmpty() ) {
-        emit validated(QByteArray());
+        emit validated(QByteArray(), QByteArray());
         return;
     }
 
@@ -148,7 +148,7 @@ void ValidateChecksumHeader::slotChecksumCalculated(const QByteArray& checksumTy
         emit validationFailed(tr("The downloaded file does not match the checksum, it will be resumed."));
         return;
     }
-    emit validated(makeChecksumHeader(checksumType, checksum));
+    emit validated(checksumType, checksum);
 }
 
 }
diff --git a/src/libsync/transmissionchecksumvalidator.h b/src/libsync/transmissionchecksumvalidator.h
index 9ae1a11..3a37c69 100644
--- a/src/libsync/transmissionchecksumvalidator.h
+++ b/src/libsync/transmissionchecksumvalidator.h
@@ -92,7 +92,7 @@ public:
     void start(const QString& filePath, const QByteArray& checksumHeader);
 
 signals:
-    void validated(const QByteArray& checksumHeader);
+    void validated(const QByteArray& checksumType, const QByteArray& checksum);
     void validationFailed( const QString& errMsg );
 
 private slots:
diff --git a/test/testsyncjournaldb.h b/test/testsyncjournaldb.h
index 7ca65b7..618b655 100644
--- a/test/testsyncjournaldb.h
+++ b/test/testsyncjournaldb.h
@@ -60,6 +60,8 @@ private slots:
         record._remotePerm = "744";
         record._mode = -17;
         record._fileSize = 213089055;
+        record._transmissionChecksum = "mychecksum";
+        record._transmissionChecksumType = "MD5";
         QVERIFY(_db.setFileRecord(record));
 
         SyncJournalFileRecord storedRecord = _db.getFileRecord("foo");
@@ -70,6 +72,31 @@ private slots:
         QVERIFY(!record.isValid());
     }
 
+    void testFileRecordChecksum()
+    {
+        // Try with and without a checksum
+        {
+            SyncJournalFileRecord record;
+            record._path = "foo-checksum";
+            record._remotePerm = "744";
+            record._transmissionChecksum = "mychecksum";
+            record._transmissionChecksumType = "MD5";
+            QVERIFY(_db.setFileRecord(record));
+
+            SyncJournalFileRecord storedRecord = _db.getFileRecord("foo-checksum");
+            QVERIFY(storedRecord == record);
+        }
+        {
+            SyncJournalFileRecord record;
+            record._path = "foo-nochecksum";
+            record._remotePerm = "744";
+            QVERIFY(_db.setFileRecord(record));
+
+            SyncJournalFileRecord storedRecord = _db.getFileRecord("foo-nochecksum");
+            QVERIFY(storedRecord == record);
+        }
+    }
+
     void testDownloadInfo()
     {
         typedef SyncJournalDb::DownloadInfo Info;
diff --git a/test/testtranschecksumvalidator.h b/test/testtranschecksumvalidator.h
index 2e08333..7c1cf43 100644
--- a/test/testtranschecksumvalidator.h
+++ b/test/testtranschecksumvalidator.h
@@ -128,7 +128,7 @@ using namespace OCC;
         _successDown = false;
 
         ValidateChecksumHeader *vali = new ValidateChecksumHeader(this);
-        connect(vali, SIGNAL(validated(QByteArray)), this, SLOT(slotDownValidated()));
+        connect(vali, SIGNAL(validated(QByteArray,QByteArray)), this, SLOT(slotDownValidated()));
         connect(vali, SIGNAL(validationFailed(QString)), this, SLOT(slotDownError(QString)));
         vali->start(_testfile, adler);
 

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