Checksums: Clearer behavior and added testing

This commit is contained in:
Christian Kamm 2017-09-15 13:30:29 +02:00 committed by Roeland Jago Douma
parent 0f21ed6a5b
commit cda72effe2
No known key found for this signature in database
GPG key ID: F941078878347C0C
4 changed files with 24 additions and 10 deletions

View file

@ -391,6 +391,7 @@ int SyncEngine::treewalkFile(csync_file_stat_t *file, csync_file_stat_t *other,
item->_instruction = instruction; item->_instruction = instruction;
item->_modtime = file->modtime; item->_modtime = file->modtime;
item->_size = file->size; item->_size = file->size;
item->_checksumHeader = file->checksumHeader;
} else { } else {
if (instruction != CSYNC_INSTRUCTION_NONE) { if (instruction != CSYNC_INSTRUCTION_NONE) {
qCWarning(lcEngine) << "ERROR: Instruction" << item->_instruction << "vs" << instruction << "for" << fileUtf8; 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; 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 // record the seen files to be able to clean the journal later
_seenFiles.insert(item->_file); _seenFiles.insert(item->_file);
if (!renameTarget.isEmpty()) { if (!renameTarget.isEmpty()) {

View file

@ -216,10 +216,12 @@ public:
QByteArray _fileId; QByteArray _fileId;
QByteArray _remotePerm; 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? // When is this set, and is it the local or the remote checksum?
// - if mtime or size changed locally for *.eml files (local checksum) // - if mtime or size changed locally for *.eml files (local checksum)
// - for potential renames of local 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; QByteArray _checksumHeader;
// The size and modtime of the file getting overwritten (on the disk for downloads, on the server for uploads). // The size and modtime of the file getting overwritten (on the disk for downloads, on the server for uploads).

View file

@ -828,6 +828,7 @@ public:
} }
OCC::SyncEngine &syncEngine() const { return *_syncEngine; } OCC::SyncEngine &syncEngine() const { return *_syncEngine; }
OCC::SyncJournalDb &syncJournal() const { return *_journalDb; }
FileModifier &localModifier() { return _localModifier; } FileModifier &localModifier() { return _localModifier; }
FileInfo &remoteModifier() { return _fakeQnam->currentRemoteState(); } FileInfo &remoteModifier() { return _fakeQnam->currentRemoteState(); }

View file

@ -103,18 +103,37 @@ private slots:
fakeFolder.localModifier().insert("a1.eml", 64, 'A'); fakeFolder.localModifier().insert("a1.eml", 64, 'A');
fakeFolder.localModifier().insert("a2.eml", 64, 'A'); fakeFolder.localModifier().insert("a2.eml", 64, 'A');
fakeFolder.localModifier().insert("a3.eml", 64, 'A'); fakeFolder.localModifier().insert("a3.eml", 64, 'A');
fakeFolder.localModifier().insert("b3.txt", 64, 'A');
// Upload and calculate the checksums // Upload and calculate the checksums
// fakeFolder.syncOnce(); // fakeFolder.syncOnce();
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 &))); QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &)));
// Touch the file without changing the content, shouldn't upload // Touch the file without changing the content, shouldn't upload
fakeFolder.localModifier().setContents("a1.eml", 'A'); fakeFolder.localModifier().setContents("a1.eml", 'A');
// Change the content/size // Change the content/size
fakeFolder.localModifier().setContents("a2.eml", 'B'); fakeFolder.localModifier().setContents("a2.eml", 'B');
fakeFolder.localModifier().appendByte("a3.eml"); fakeFolder.localModifier().appendByte("a3.eml");
fakeFolder.localModifier().appendByte("b3.txt");
fakeFolder.syncOnce(); 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(!itemDidComplete(completeSpy, "a1.eml"));
QVERIFY(itemDidCompleteSuccessfully(completeSpy, "a2.eml")); QVERIFY(itemDidCompleteSuccessfully(completeSpy, "a2.eml"));
QVERIFY(itemDidCompleteSuccessfully(completeSpy, "a3.eml")); QVERIFY(itemDidCompleteSuccessfully(completeSpy, "a3.eml"));