Vfs suffix: Fix dehydration creating the wrong db entry

This commit is contained in:
Christian Kamm 2019-02-06 15:07:54 +01:00 committed by Kevin Ottens
parent b06f67baf0
commit 8a8e93827f
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
5 changed files with 27 additions and 7 deletions

View file

@ -961,12 +961,19 @@ void ProcessDirectoryJob::processFileFinalize(
QueryMode recurseQueryLocal, QueryMode recurseQueryServer)
{
// Adjust target path for virtual-suffix files
if (item->_type == ItemTypeVirtualFile && isVfsWithSuffix()) {
addVirtualFileSuffix(path._target);
if (item->_instruction == CSYNC_INSTRUCTION_RENAME)
if (isVfsWithSuffix()) {
if (item->_type == ItemTypeVirtualFile) {
addVirtualFileSuffix(path._target);
if (item->_instruction == CSYNC_INSTRUCTION_RENAME)
addVirtualFileSuffix(item->_renameTarget);
else
addVirtualFileSuffix(item->_file);
}
if (item->_type == ItemTypeVirtualFileDehydration
&& item->_instruction == CSYNC_INSTRUCTION_NEW) {
item->_renameTarget = item->_file;
addVirtualFileSuffix(item->_renameTarget);
else
addVirtualFileSuffix(item->_file);
}
}
if (path._original != path._target && (item->_instruction == CSYNC_INSTRUCTION_UPDATE_METADATA || item->_instruction == CSYNC_INSTRUCTION_NONE)) {

View file

@ -429,7 +429,9 @@ void PropagateDownloadFile::startAfterIsEncryptedIsChecked()
qCDebug(lcPropagateDownload) << "dehydrating file" << _item->_file;
_item->_type = ItemTypeVirtualFile; // Needed?
vfs->dehydratePlaceholder(*_item);
propagator()->_journal->deleteFileRecord(_item->_file);
propagator()->_journal->deleteFileRecord(_item->_originalFile);
if (!_item->_renameTarget.isEmpty())
_item->_file = _item->_renameTarget;
updateMetadata(false);
return;
}

View file

@ -197,6 +197,8 @@ public:
// Variables useful for everybody
QString _file;
// for renames: the name _file should be renamed to
// for dehydrations: the name _file should become after dehydration (like adding a suffix)
QString _renameTarget;
/// Whether there's end to end encryption on this file.

View file

@ -74,7 +74,7 @@ void VfsSuffix::dehydratePlaceholder(const SyncFileItem &item)
{
QFile::remove(_setupParams.filesystemPath + item._file);
SyncFileItem virtualItem(item);
virtualItem._file.append(fileSuffix());
virtualItem._file = item._renameTarget;
createPlaceholder(virtualItem);
}

View file

@ -668,9 +668,17 @@ private slots:
return !fakeFolder.currentLocalState().find(path)
&& fakeFolder.currentLocalState().find(placeholder);
};
auto hasDehydratedDbEntries = [&](const QString &path) {
SyncJournalFileRecord normal, suffix;
fakeFolder.syncJournal().getFileRecord(path, &normal);
fakeFolder.syncJournal().getFileRecord(path + ".nextcloud", &suffix);
return !normal.isValid() && suffix.isValid() && suffix._type == ItemTypeVirtualFile;
};
QVERIFY(isDehydrated("A/a1"));
QVERIFY(hasDehydratedDbEntries("A/a1"));
QVERIFY(isDehydrated("A/a2"));
QVERIFY(hasDehydratedDbEntries("A/a2"));
QVERIFY(!fakeFolder.currentLocalState().find("B/b1"));
QVERIFY(!fakeFolder.currentRemoteState().find("B/b1"));
@ -679,6 +687,7 @@ private slots:
QVERIFY(!fakeFolder.currentLocalState().find("B/b2"));
QVERIFY(!fakeFolder.currentRemoteState().find("B/b2"));
QVERIFY(isDehydrated("B/b3"));
QVERIFY(hasDehydratedDbEntries("B/b3"));
QVERIFY(itemInstruction(completeSpy, "B/b2", CSYNC_INSTRUCTION_REMOVE));
QVERIFY(itemInstruction(completeSpy, "B/b3.nextcloud", CSYNC_INSTRUCTION_NEW));