Checksums: Clearer behavior and added testing
authorChristian Kamm <mail@ckamm.de>
Fri, 15 Sep 2017 11:30:29 +0000 (13:30 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Thu, 5 Oct 2017 20:01:33 +0000 (22:01 +0200)
src/libsync/syncengine.cpp
src/libsync/syncfileitem.h
test/syncenginetestutils.h
test/testsyncengine.cpp

index f42b5d2d7626f4e77e4b2f55932c3384e60af138..a2afbedde093e35771aaa69de2a2df489395df50 100644 (file)
@@ -391,6 +391,7 @@ int SyncEngine::treewalkFile(csync_file_stat_t *file, csync_file_stat_t *other,
         item->_instruction = instruction;
         item->_modtime = file->modtime;
         item->_size = file->size;
+        item->_checksumHeader = file->checksumHeader;
     } else {
         if (instruction != CSYNC_INSTRUCTION_NONE) {
             qCWarning(lcEngine) << "ERROR: Instruction" << item->_instruction << "vs" << instruction << "for" << fileUtf8;
@@ -429,15 +430,6 @@ int SyncEngine::treewalkFile(csync_file_stat_t *file, csync_file_stat_t *other,
         item->_serverHasIgnoredFiles = file->has_ignored_files;
     }
 
-    // Sometimes the discovery computes checksums for local files
-    if (!remote && !file->checksumHeader.isEmpty()) {
-        item->_checksumHeader = file->checksumHeader;
-    }
-    // For conflicts, store the remote checksum there
-    if (remote && item->_instruction == CSYNC_INSTRUCTION_CONFLICT && !file->checksumHeader.isEmpty()) {
-        item->_checksumHeader = file->checksumHeader;
-    }
-
     // record the seen files to be able to clean the journal later
     _seenFiles.insert(item->_file);
     if (!renameTarget.isEmpty()) {
index 88ef5ee6dfc0d9c1f5a8c5757c43fae39e484788..8c546038a1996a3616ff7077b0a9e22b9de466e9 100644 (file)
@@ -216,10 +216,12 @@ public:
     QByteArray _fileId;
     QByteArray _remotePerm;
 
+    // This is the value for the 'new' side, matching with _size and _modtime.
+    //
     // When is this set, and is it the local or the remote checksum?
     // - if mtime or size changed locally for *.eml files (local checksum)
     // - for potential renames of local files (local checksum)
-    // - for conflicts (remote checksum) (what about eval_rename/new reconcile?)
+    // - for conflicts (remote checksum)
     QByteArray _checksumHeader;
 
     // The size and modtime of the file getting overwritten (on the disk for downloads, on the server for uploads).
index c2a0c0c8bf92e6e11ef45882c4575428dfaef093..3fb03324f7be1ffcdce5873351076b3e74934ce4 100644 (file)
@@ -828,6 +828,7 @@ public:
     }
 
     OCC::SyncEngine &syncEngine() const { return *_syncEngine; }
+    OCC::SyncJournalDb &syncJournal() const { return *_journalDb; }
 
     FileModifier &localModifier() { return _localModifier; }
     FileInfo &remoteModifier() { return _fakeQnam->currentRemoteState(); }
index d96c40695219164995023f3ba15ebfaf68e2d4e8..9de20a015496ce7bafe9f963102b3a390f9a748f 100644 (file)
@@ -103,18 +103,37 @@ private slots:
         fakeFolder.localModifier().insert("a1.eml", 64, 'A');
         fakeFolder.localModifier().insert("a2.eml", 64, 'A');
         fakeFolder.localModifier().insert("a3.eml", 64, 'A');
+        fakeFolder.localModifier().insert("b3.txt", 64, 'A');
         // Upload and calculate the checksums
         // fakeFolder.syncOnce();
         fakeFolder.syncOnce();
 
+        auto getDbChecksum = [&](QString path) {
+            auto record = fakeFolder.syncJournal().getFileRecord(path);
+            return record._checksumHeader;
+        };
+
+        // printf 'A%.0s' {1..64} | sha1sum -
+        QByteArray referenceChecksum("SHA1:30b86e44e6001403827a62c58b08893e77cf121f");
+        QCOMPARE(getDbChecksum("a1.eml"), referenceChecksum);
+        QCOMPARE(getDbChecksum("a2.eml"), referenceChecksum);
+        QCOMPARE(getDbChecksum("a3.eml"), referenceChecksum);
+        QCOMPARE(getDbChecksum("b3.txt"), referenceChecksum);
+
         QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
         // Touch the file without changing the content, shouldn't upload
         fakeFolder.localModifier().setContents("a1.eml", 'A');
         // Change the content/size
         fakeFolder.localModifier().setContents("a2.eml", 'B');
         fakeFolder.localModifier().appendByte("a3.eml");
+        fakeFolder.localModifier().appendByte("b3.txt");
         fakeFolder.syncOnce();
 
+        QCOMPARE(getDbChecksum("a1.eml"), referenceChecksum);
+        QCOMPARE(getDbChecksum("a2.eml"), QByteArray("SHA1:84951fc23a4dafd10020ac349da1f5530fa65949"));
+        QCOMPARE(getDbChecksum("a3.eml"), QByteArray("SHA1:826b7e7a7af8a529ae1c7443c23bf185c0ad440c"));
+        QCOMPARE(getDbChecksum("b3.eml"), getDbChecksum("a3.txt"));
+
         QVERIFY(!itemDidComplete(completeSpy, "a1.eml"));
         QVERIFY(itemDidCompleteSuccessfully(completeSpy, "a2.eml"));
         QVERIFY(itemDidCompleteSuccessfully(completeSpy, "a3.eml"));