mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-22 13:05:51 +03:00
vfs: Use PinState in sync algorithm #6815
New files are virtual if the file's pin state is OnlineOnly.
This commit is contained in:
parent
68126ac208
commit
486c25cb47
3 changed files with 77 additions and 1 deletions
|
@ -400,7 +400,10 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
|
|||
}
|
||||
// Turn new remote files into virtual files if the option is enabled.
|
||||
auto &opts = _discoveryData->_syncOptions;
|
||||
if (!localEntry.isValid() && opts._vfs->mode() != Vfs::Off && opts._newFilesAreVirtual && item->_type == ItemTypeFile) {
|
||||
if (!localEntry.isValid()
|
||||
&& item->_type == ItemTypeFile
|
||||
&& opts._vfs->mode() != Vfs::Off
|
||||
&& directoryPinState() == PinState::OnlineOnly) {
|
||||
item->_type = ItemTypeVirtualFile;
|
||||
if (isVfsWithSuffix())
|
||||
addVirtualFileSuffix(path._original);
|
||||
|
@ -1318,6 +1321,19 @@ bool ProcessDirectoryJob::runLocalQuery()
|
|||
return true;
|
||||
}
|
||||
|
||||
PinState ProcessDirectoryJob::directoryPinState()
|
||||
{
|
||||
if (_pinStateCache)
|
||||
return *_pinStateCache;
|
||||
|
||||
// Get the path's pinstate and anchor to the root option
|
||||
_pinStateCache = _discoveryData->_statedb->pinStateForPath(_currentFolder._original.toUtf8());
|
||||
if (*_pinStateCache == PinState::Unspecified)
|
||||
_pinStateCache = _discoveryData->_syncOptions._newFilesAreVirtual ? PinState::OnlineOnly : PinState::AlwaysLocal;
|
||||
|
||||
return *_pinStateCache;
|
||||
}
|
||||
|
||||
bool ProcessDirectoryJob::isVfsWithSuffix() const
|
||||
{
|
||||
return _discoveryData->_syncOptions._vfs->mode() == Vfs::WithSuffix;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "discoveryphase.h"
|
||||
#include "syncfileitem.h"
|
||||
#include "common/asserts.h"
|
||||
#include "common/syncjournaldb.h"
|
||||
|
||||
class ExcludedFiles;
|
||||
|
||||
|
@ -177,6 +178,9 @@ private:
|
|||
*/
|
||||
bool runLocalQuery();
|
||||
|
||||
/** Retrieve and cache directory pin state */
|
||||
PinState directoryPinState();
|
||||
|
||||
QueryMode _queryServer;
|
||||
QueryMode _queryLocal;
|
||||
|
||||
|
@ -216,6 +220,7 @@ private:
|
|||
PathTuple _currentFolder;
|
||||
bool _childModified = false; // the directory contains modified item what would prevent deletion
|
||||
bool _childIgnored = false; // The directory contains ignored item that would prevent deletion
|
||||
Optional<PinState> _pinStateCache; // The directories pin-state, once retrieved, see directoryPinState()
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
|
|
|
@ -739,6 +739,61 @@ private slots:
|
|||
QVERIFY(fakeFolder.currentRemoteState().find("A/a3.nextcloud")); // regular upload
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
}
|
||||
|
||||
void testNewVirtuals()
|
||||
{
|
||||
FakeFolder fakeFolder{ FileInfo() };
|
||||
SyncOptions syncOptions = vfsSyncOptions();
|
||||
syncOptions._newFilesAreVirtual = true;
|
||||
fakeFolder.syncEngine().setSyncOptions(syncOptions);
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
|
||||
auto setPin = [&] (const QByteArray &path, PinState state) {
|
||||
fakeFolder.syncJournal().setPinStateForPath(path, state);
|
||||
};
|
||||
|
||||
fakeFolder.remoteModifier().mkdir("local");
|
||||
fakeFolder.remoteModifier().mkdir("online");
|
||||
fakeFolder.remoteModifier().mkdir("unspec");
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
|
||||
setPin("local", PinState::AlwaysLocal);
|
||||
setPin("online", PinState::OnlineOnly);
|
||||
|
||||
// Test 1: root is OnlineOnly
|
||||
fakeFolder.remoteModifier().insert("file1");
|
||||
fakeFolder.remoteModifier().insert("online/file1");
|
||||
fakeFolder.remoteModifier().insert("local/file1");
|
||||
fakeFolder.remoteModifier().insert("unspec/file1");
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
|
||||
QVERIFY(fakeFolder.currentLocalState().find("file1.nextcloud"));
|
||||
QVERIFY(fakeFolder.currentLocalState().find("online/file1.nextcloud"));
|
||||
QVERIFY(fakeFolder.currentLocalState().find("local/file1"));
|
||||
QVERIFY(fakeFolder.currentLocalState().find("unspec/file1.nextcloud"));
|
||||
|
||||
// Test 2: root is AlwaysLocal
|
||||
syncOptions._newFilesAreVirtual = false;
|
||||
fakeFolder.syncEngine().setSyncOptions(syncOptions);
|
||||
|
||||
fakeFolder.remoteModifier().insert("file2");
|
||||
fakeFolder.remoteModifier().insert("online/file2");
|
||||
fakeFolder.remoteModifier().insert("local/file2");
|
||||
fakeFolder.remoteModifier().insert("unspec/file2");
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
|
||||
QVERIFY(fakeFolder.currentLocalState().find("file2"));
|
||||
QVERIFY(fakeFolder.currentLocalState().find("online/file2.nextcloud"));
|
||||
QVERIFY(fakeFolder.currentLocalState().find("local/file2"));
|
||||
QVERIFY(fakeFolder.currentLocalState().find("unspec/file2"));
|
||||
|
||||
// file1 is unchanged
|
||||
QVERIFY(fakeFolder.currentLocalState().find("file1.nextcloud"));
|
||||
QVERIFY(fakeFolder.currentLocalState().find("online/file1.nextcloud"));
|
||||
QVERIFY(fakeFolder.currentLocalState().find("local/file1"));
|
||||
QVERIFY(fakeFolder.currentLocalState().find("unspec/file1.nextcloud"));
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(TestSyncVirtualFiles)
|
||||
|
|
Loading…
Reference in a new issue