Просмотр исходного кода

Vfs: Move pin state if files move #7250

Previously renames of items didn't carry the pin state with them.
Christian Kamm 6 лет назад
Родитель
Сommit
fb47419e84
4 измененных файлов с 44 добавлено и 3 удалено
  1. 2 1
      src/common/vfs.cpp
  2. 13 2
      src/libsync/propagateremotemove.cpp
  3. 9 0
      src/libsync/propagatorjobs.cpp
  4. 20 0
      test/testsyncvirtualfiles.cpp

+ 2 - 1
src/common/vfs.cpp

@@ -70,7 +70,8 @@ bool Vfs::setPinStateInDb(const QString &folderPath, PinState state)
 {
 {
     auto path = folderPath.toUtf8();
     auto path = folderPath.toUtf8();
     _setupParams.journal->internalPinStates().wipeForPathAndBelow(path);
     _setupParams.journal->internalPinStates().wipeForPathAndBelow(path);
-    _setupParams.journal->internalPinStates().setForPath(path, state);
+    if (state != PinState::Inherited)
+        _setupParams.journal->internalPinStates().setForPath(path, state);
     return true;
     return true;
 }
 }
 
 

+ 13 - 2
src/libsync/propagateremotemove.cpp

@@ -199,13 +199,19 @@ void PropagateRemoteMove::slotMoveJobFinished()
 
 
 void PropagateRemoteMove::finalize()
 void PropagateRemoteMove::finalize()
 {
 {
-    SyncJournalFileRecord oldRecord;
-    propagator()->_journal->getFileRecord(_item->_originalFile, &oldRecord);
+    // Retrieve old db data.
     // if reading from db failed still continue hoping that deleteFileRecord
     // if reading from db failed still continue hoping that deleteFileRecord
     // reopens the db successfully.
     // reopens the db successfully.
     // The db is only queried to transfer the content checksum from the old
     // The db is only queried to transfer the content checksum from the old
     // to the new record. It is not a problem to skip it here.
     // to the new record. It is not a problem to skip it here.
+    SyncJournalFileRecord oldRecord;
+    propagator()->_journal->getFileRecord(_item->_originalFile, &oldRecord);
+    auto &vfs = propagator()->syncOptions()._vfs;
+    auto pinState = vfs->pinState(_item->_originalFile);
+
+    // Delete old db data.
     propagator()->_journal->deleteFileRecord(_item->_originalFile);
     propagator()->_journal->deleteFileRecord(_item->_originalFile);
+    vfs->setPinState(_item->_originalFile, PinState::Inherited);
 
 
     SyncFileItem newItem(*_item);
     SyncFileItem newItem(*_item);
     newItem._type = _item->_type;
     newItem._type = _item->_type;
@@ -222,6 +228,11 @@ void PropagateRemoteMove::finalize()
         done(SyncFileItem::FatalError, tr("Error writing metadata to the database"));
         done(SyncFileItem::FatalError, tr("Error writing metadata to the database"));
         return;
         return;
     }
     }
+    if (pinState && *pinState != PinState::Inherited
+        && !vfs->setPinState(newItem._renameTarget, *pinState)) {
+        done(SyncFileItem::NormalError, tr("Error setting pin state"));
+        return;
+    }
 
 
     if (_item->isDirectory()) {
     if (_item->isDirectory()) {
         propagator()->_renamedDirectories.insert(_item->_file, _item->_renameTarget);
         propagator()->_renamedDirectories.insert(_item->_file, _item->_renameTarget);

+ 9 - 0
src/libsync/propagatorjobs.cpp

@@ -283,6 +283,10 @@ void PropagateLocalRename::start()
     propagator()->_journal->getFileRecord(_item->_originalFile, &oldRecord);
     propagator()->_journal->getFileRecord(_item->_originalFile, &oldRecord);
     propagator()->_journal->deleteFileRecord(_item->_originalFile);
     propagator()->_journal->deleteFileRecord(_item->_originalFile);
 
 
+    auto &vfs = propagator()->syncOptions()._vfs;
+    auto pinState = vfs->pinState(_item->_originalFile);
+    vfs->setPinState(_item->_originalFile, PinState::Inherited);
+
     const auto oldFile = _item->_file;
     const auto oldFile = _item->_file;
 
 
     if (!_item->isDirectory()) { // Directories are saved at the end
     if (!_item->isDirectory()) { // Directories are saved at the end
@@ -301,6 +305,11 @@ void PropagateLocalRename::start()
             return;
             return;
         }
         }
     }
     }
+    if (pinState && *pinState != PinState::Inherited
+        && !vfs->setPinState(_item->_renameTarget, *pinState)) {
+        done(SyncFileItem::NormalError, tr("Error setting pin state"));
+        return;
+    }
 
 
     propagator()->_journal->commit("localRename");
     propagator()->_journal->commit("localRename");
 
 

+ 20 - 0
test/testsyncvirtualfiles.cpp

@@ -1128,6 +1128,26 @@ private slots:
         // Sync again: bad pin states of new local files usually take effect on second sync
         // Sync again: bad pin states of new local files usually take effect on second sync
         QVERIFY(fakeFolder.syncOnce());
         QVERIFY(fakeFolder.syncOnce());
         QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
         QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
+
+        // When a file in an online-only folder is renamed, it retains its pin
+        fakeFolder.localModifier().rename("online/file1", "online/file1rename");
+        fakeFolder.remoteModifier().rename("online/file2", "online/file2rename");
+        QVERIFY(fakeFolder.syncOnce());
+        QCOMPARE(*vfs->pinState("online/file1rename"), PinState::Unspecified);
+        QCOMPARE(*vfs->pinState("online/file2rename"), PinState::Unspecified);
+
+        // When a folder is renamed, the pin states inside should be retained
+        fakeFolder.localModifier().rename("online", "onlinerenamed1");
+        QVERIFY(fakeFolder.syncOnce());
+        QCOMPARE(*vfs->pinState("onlinerenamed1"), PinState::OnlineOnly);
+        QCOMPARE(*vfs->pinState("onlinerenamed1/file1rename"), PinState::Unspecified);
+
+        fakeFolder.remoteModifier().rename("onlinerenamed1", "onlinerenamed2");
+        QVERIFY(fakeFolder.syncOnce());
+        QCOMPARE(*vfs->pinState("onlinerenamed2"), PinState::OnlineOnly);
+        QCOMPARE(*vfs->pinState("onlinerenamed2/file1rename"), PinState::Unspecified);
+
+        QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
     }
     }
 };
 };