mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-24 22:15:57 +03:00
Merge pull request #7334 from nextcloud/bugfix/useFileIdToTrackRenamedItems
Bugfix/use file id to track renamed items
This commit is contained in:
commit
b59c7b4aa0
5 changed files with 9 additions and 55 deletions
|
@ -912,9 +912,8 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(const SyncFileItemPtr &it
|
||||||
done = true;
|
done = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!serverEntry.isDirectory && base._etag != serverEntry.etag) {
|
if (!serverEntry.isDirectory && (base._modtime != serverEntry.modtime || base._fileSize != serverEntry.size)) {
|
||||||
/* File with different etag, don't do a rename, but download the file again */
|
qCInfo(lcDisco, "file metadata different, forcing a download of the new file");
|
||||||
qCInfo(lcDisco, "file etag different, not a rename");
|
|
||||||
done = true;
|
done = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1595,7 +1594,7 @@ void ProcessDirectoryJob::processFileConflict(const SyncFileItemPtr &item, Proce
|
||||||
// If there's no content hash, use heuristics
|
// If there's no content hash, use heuristics
|
||||||
if (serverEntry.checksumHeader.isEmpty()) {
|
if (serverEntry.checksumHeader.isEmpty()) {
|
||||||
// If the size or mtime is different, it's definitely a conflict.
|
// If the size or mtime is different, it's definitely a conflict.
|
||||||
bool isConflict = (serverEntry.size != localEntry.size) || (serverEntry.modtime != localEntry.modtime);
|
bool isConflict = (serverEntry.size != localEntry.size) || (serverEntry.modtime != localEntry.modtime) || (dbEntry.isValid() && dbEntry._modtime != localEntry.modtime && serverEntry.modtime == localEntry.modtime);
|
||||||
|
|
||||||
// It could be a conflict even if size and mtime match!
|
// It could be a conflict even if size and mtime match!
|
||||||
//
|
//
|
||||||
|
|
|
@ -178,6 +178,7 @@ void FileInfo::setContents(const QString &relativePath, char contentChar)
|
||||||
FileInfo *file = findInvalidatingEtags(relativePath);
|
FileInfo *file = findInvalidatingEtags(relativePath);
|
||||||
Q_ASSERT(file);
|
Q_ASSERT(file);
|
||||||
file->contentChar = contentChar;
|
file->contentChar = contentChar;
|
||||||
|
file->lastModified = QDateTime::currentDateTimeUtc();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileInfo::appendByte(const QString &relativePath)
|
void FileInfo::appendByte(const QString &relativePath)
|
||||||
|
|
|
@ -328,35 +328,22 @@ private slots:
|
||||||
fakeFolder.localModifier().insert("A/a0", size);
|
fakeFolder.localModifier().insert("A/a0", size);
|
||||||
QVERIFY(!fakeFolder.syncOnce()); // error: abort!
|
QVERIFY(!fakeFolder.syncOnce()); // error: abort!
|
||||||
|
|
||||||
// Now the next sync gets a NEW/NEW conflict and since there's no checksum
|
|
||||||
// it just becomes a UPDATE_METADATA
|
|
||||||
auto checkEtagUpdated = [&](SyncFileItemVector &items) {
|
|
||||||
QCOMPARE(items.size(), 1);
|
|
||||||
QCOMPARE(items[0]->_file, QLatin1String("A"));
|
|
||||||
SyncJournalFileRecord record;
|
|
||||||
QVERIFY(fakeFolder.syncJournal().getFileRecord(QByteArray("A/a0"), &record));
|
|
||||||
QCOMPARE(record._etag, fakeFolder.remoteModifier().find("A/a0")->etag);
|
|
||||||
};
|
|
||||||
auto connection = connect(&fakeFolder.syncEngine(), &SyncEngine::aboutToPropagate, checkEtagUpdated);
|
|
||||||
QVERIFY(fakeFolder.syncOnce());
|
QVERIFY(fakeFolder.syncOnce());
|
||||||
disconnect(connection);
|
|
||||||
QCOMPARE(nGET, 0);
|
QCOMPARE(nGET, 0);
|
||||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||||
|
|
||||||
|
|
||||||
// Test 2: modified file upload aborted
|
// Test 2: modified file upload aborted
|
||||||
|
nGET = 0;
|
||||||
fakeFolder.localModifier().appendByte("A/a0");
|
fakeFolder.localModifier().appendByte("A/a0");
|
||||||
QVERIFY(!fakeFolder.syncOnce()); // error: abort!
|
QVERIFY(!fakeFolder.syncOnce()); // error: abort!
|
||||||
|
|
||||||
// An EVAL/EVAL conflict is also UPDATE_METADATA when there's no checksums
|
// An EVAL/EVAL conflict is also UPDATE_METADATA when there's no checksums
|
||||||
connection = connect(&fakeFolder.syncEngine(), &SyncEngine::aboutToPropagate, checkEtagUpdated);
|
|
||||||
QVERIFY(fakeFolder.syncOnce());
|
QVERIFY(fakeFolder.syncOnce());
|
||||||
disconnect(connection);
|
QCOMPARE(nGET, 1);
|
||||||
QCOMPARE(nGET, 0);
|
|
||||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||||
|
|
||||||
|
|
||||||
// Test 3: modified file upload aborted, with good checksums
|
// Test 3: modified file upload aborted, with good checksums
|
||||||
|
nGET = 0;
|
||||||
fakeFolder.localModifier().appendByte("A/a0");
|
fakeFolder.localModifier().appendByte("A/a0");
|
||||||
QVERIFY(!fakeFolder.syncOnce()); // error: abort!
|
QVERIFY(!fakeFolder.syncOnce()); // error: abort!
|
||||||
|
|
||||||
|
@ -365,12 +352,11 @@ private slots:
|
||||||
fakeFolder.remoteModifier().find("A/a0")->checksums = moveChecksumHeader;
|
fakeFolder.remoteModifier().find("A/a0")->checksums = moveChecksumHeader;
|
||||||
|
|
||||||
QVERIFY(fakeFolder.syncOnce());
|
QVERIFY(fakeFolder.syncOnce());
|
||||||
disconnect(connection);
|
|
||||||
QCOMPARE(nGET, 0); // no new download, just a metadata update!
|
QCOMPARE(nGET, 0); // no new download, just a metadata update!
|
||||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||||
|
|
||||||
|
|
||||||
// Test 4: New file, that gets deleted locally before the next sync
|
// Test 4: New file, that gets deleted locally before the next sync
|
||||||
|
nGET = 0;
|
||||||
fakeFolder.localModifier().insert("A/a3", size);
|
fakeFolder.localModifier().insert("A/a3", size);
|
||||||
QVERIFY(!fakeFolder.syncOnce()); // error: abort!
|
QVERIFY(!fakeFolder.syncOnce()); // error: abort!
|
||||||
fakeFolder.localModifier().remove("A/a3");
|
fakeFolder.localModifier().remove("A/a3");
|
||||||
|
|
|
@ -432,7 +432,7 @@ private slots:
|
||||||
|
|
||||||
QTest::newRow("Same mtime, but no server checksum -> ignored in reconcile")
|
QTest::newRow("Same mtime, but no server checksum -> ignored in reconcile")
|
||||||
<< true << QByteArray()
|
<< true << QByteArray()
|
||||||
<< 0;
|
<< 1;
|
||||||
|
|
||||||
QTest::newRow("Same mtime, weak server checksum differ -> downloaded")
|
QTest::newRow("Same mtime, weak server checksum differ -> downloaded")
|
||||||
<< true << QByteArray("Adler32:bad")
|
<< true << QByteArray("Adler32:bad")
|
||||||
|
|
|
@ -741,38 +741,6 @@ private slots:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/owncloud/client/issues/6629#issuecomment-402450691
|
|
||||||
// When a file is moved and the server mtime was not in sync, the local mtime should be kept
|
|
||||||
void testMoveAndMTimeChange()
|
|
||||||
{
|
|
||||||
FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
|
|
||||||
OperationCounter counter;
|
|
||||||
fakeFolder.setServerOverride(counter.functor());
|
|
||||||
|
|
||||||
// Changing the mtime on the server (without invalidating the etag)
|
|
||||||
fakeFolder.remoteModifier().find("A/a1")->lastModified = QDateTime::currentDateTimeUtc().addSecs(-50000);
|
|
||||||
fakeFolder.remoteModifier().find("A/a2")->lastModified = QDateTime::currentDateTimeUtc().addSecs(-40000);
|
|
||||||
|
|
||||||
// Move a few files
|
|
||||||
fakeFolder.remoteModifier().rename("A/a1", "A/a1_server_renamed");
|
|
||||||
fakeFolder.localModifier().rename("A/a2", "A/a2_local_renamed");
|
|
||||||
|
|
||||||
QVERIFY(fakeFolder.syncOnce());
|
|
||||||
QCOMPARE(counter.nGET, 0);
|
|
||||||
QCOMPARE(counter.nPUT, 0);
|
|
||||||
QCOMPARE(counter.nMOVE, 1);
|
|
||||||
QCOMPARE(counter.nDELETE, 0);
|
|
||||||
|
|
||||||
// Another sync should do nothing
|
|
||||||
QVERIFY(fakeFolder.syncOnce());
|
|
||||||
QCOMPARE(counter.nGET, 0);
|
|
||||||
QCOMPARE(counter.nPUT, 0);
|
|
||||||
QCOMPARE(counter.nMOVE, 1);
|
|
||||||
QCOMPARE(counter.nDELETE, 0);
|
|
||||||
|
|
||||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test for https://github.com/owncloud/client/issues/6694
|
// Test for https://github.com/owncloud/client/issues/6694
|
||||||
void testInvertFolderHierarchy()
|
void testInvertFolderHierarchy()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue