Vfs: Remove old db record when dehydrating via rename
authorChristian Kamm <mail@ckamm.de>
Wed, 24 Jul 2019 14:07:28 +0000 (16:07 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:54 +0000 (10:58 +0100)
For #7338

src/libsync/discovery.cpp
test/testsyncvirtualfiles.cpp

index 97a5e9aca4f15ab5d65f8dcd8d960b041504d706..8472b819d546ab06cb71276a01aa0bf9fde43f82 100644 (file)
@@ -720,8 +720,10 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
                 if (dbEntry._modtime == localEntry.modtime && dbEntry._fileSize == localEntry.size) {
                     qCInfo(lcDisco) << "Base file was renamed to virtual file:" << item->_file;
                     item->_direction = SyncFileItem::Down;
-                    item->_instruction = CSYNC_INSTRUCTION_NEW;
-                    item->_type = ItemTypeVirtualFile;
+                    item->_instruction = CSYNC_INSTRUCTION_SYNC;
+                    item->_type = ItemTypeVirtualFileDehydration;
+                    addVirtualFileSuffix(item->_file);
+                    item->_renameTarget = item->_file;
                 } else {
                     qCInfo(lcDisco) << "Virtual file with non-virtual db entry, ignoring:" << item->_file;
                     item->_instruction = CSYNC_INSTRUCTION_IGNORE;
@@ -1058,8 +1060,10 @@ void ProcessDirectoryJob::processFileFinalize(
         }
         if (item->_type == ItemTypeVirtualFileDehydration
             && item->_instruction == CSYNC_INSTRUCTION_SYNC) {
-            item->_renameTarget = item->_file;
-            addVirtualFileSuffix(item->_renameTarget);
+            if (item->_renameTarget.isEmpty()) {
+                item->_renameTarget = item->_file;
+                addVirtualFileSuffix(item->_renameTarget);
+            }
         }
     }
 
index 323c52b36ab8eb638e23862f73c54f0060ce3624..9f2477049e4ee505c5a1977e1edb98fa7f364ebc 100644 (file)
@@ -402,6 +402,7 @@ private slots:
         QVERIFY(itemInstruction(completeSpy, "A/b4m" DVSUFFIX, CSYNC_INSTRUCTION_NEW));
         QVERIFY(itemInstruction(completeSpy, "A/b4", CSYNC_INSTRUCTION_REMOVE));
         QCOMPARE(dbRecord(fakeFolder, "A/a1")._type, ItemTypeFile);
+        QVERIFY(!dbRecord(fakeFolder, "A/a1" DVSUFFIX).isValid());
         QCOMPARE(dbRecord(fakeFolder, "A/a2")._type, ItemTypeFile);
         QVERIFY(!dbRecord(fakeFolder, "A/a3").isValid());
         QCOMPARE(dbRecord(fakeFolder, "A/a4m")._type, ItemTypeFile);
@@ -409,6 +410,7 @@ private slots:
         QCOMPARE(dbRecord(fakeFolder, "A/a6")._type, ItemTypeFile);
         QCOMPARE(dbRecord(fakeFolder, "A/a7")._type, ItemTypeFile);
         QCOMPARE(dbRecord(fakeFolder, "A/b1")._type, ItemTypeFile);
+        QVERIFY(!dbRecord(fakeFolder, "A/b1" DVSUFFIX).isValid());
         QCOMPARE(dbRecord(fakeFolder, "A/b2")._type, ItemTypeFile);
         QVERIFY(!dbRecord(fakeFolder, "A/b3").isValid());
         QCOMPARE(dbRecord(fakeFolder, "A/b4m" DVSUFFIX)._type, ItemTypeVirtualFile);
@@ -612,8 +614,9 @@ private slots:
         QVERIFY(!fakeFolder.currentLocalState().find("A/a1"));
         QVERIFY(fakeFolder.currentLocalState().find("A/a1" DVSUFFIX));
         QVERIFY(fakeFolder.currentRemoteState().find("A/a1"));
-        QVERIFY(itemInstruction(completeSpy, "A/a1" DVSUFFIX, CSYNC_INSTRUCTION_NEW));
+        QVERIFY(itemInstruction(completeSpy, "A/a1" DVSUFFIX, CSYNC_INSTRUCTION_SYNC));
         QCOMPARE(dbRecord(fakeFolder, "A/a1" DVSUFFIX)._type, ItemTypeVirtualFile);
+        QVERIFY(!dbRecord(fakeFolder, "A/a1").isValid());
 
         QVERIFY(!fakeFolder.currentLocalState().find("A/a2"));
         QVERIFY(!fakeFolder.currentLocalState().find("A/a2" DVSUFFIX));