From 8a8e93827f53ef0349d883c61b7d05ea429a697d Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Wed, 6 Feb 2019 15:07:54 +0100 Subject: [PATCH] Vfs suffix: Fix dehydration creating the wrong db entry --- src/libsync/discovery.cpp | 17 ++++++++++++----- src/libsync/propagatedownload.cpp | 4 +++- src/libsync/syncfileitem.h | 2 ++ src/libsync/vfs/suffix/vfs_suffix.cpp | 2 +- test/testsyncvirtualfiles.cpp | 9 +++++++++ 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 28f2140b1..51dc164dd 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -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)) { diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index da9d8435e..c0984d55e 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -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; } diff --git a/src/libsync/syncfileitem.h b/src/libsync/syncfileitem.h index 486826710..6e0fe86c4 100644 --- a/src/libsync/syncfileitem.h +++ b/src/libsync/syncfileitem.h @@ -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. diff --git a/src/libsync/vfs/suffix/vfs_suffix.cpp b/src/libsync/vfs/suffix/vfs_suffix.cpp index ca5da6d25..daf20dd83 100644 --- a/src/libsync/vfs/suffix/vfs_suffix.cpp +++ b/src/libsync/vfs/suffix/vfs_suffix.cpp @@ -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); } diff --git a/test/testsyncvirtualfiles.cpp b/test/testsyncvirtualfiles.cpp index afa9f426e..b2b3ef239 100644 --- a/test/testsyncvirtualfiles.cpp +++ b/test/testsyncvirtualfiles.cpp @@ -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));