mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-29 20:28:57 +03:00
Checksums: Clearer behavior and added testing
This commit is contained in:
parent
0f21ed6a5b
commit
cda72effe2
4 changed files with 24 additions and 10 deletions
|
@ -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()) {
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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"));
|
||||
|
|
Loading…
Reference in a new issue