Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyncEngine: SelectiveSync: Remove local files of undelected folder de… #5822

Merged
merged 1 commit into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
bool selectiveListOk;
auto selectiveSyncBlackList = _journal->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &selectiveListOk);
std::sort(selectiveSyncBlackList.begin(), selectiveSyncBlackList.end());
SyncFileItemPtr needle;

for (SyncFileItemVector::iterator it = syncItems.begin(); it != syncItems.end(); ++it) {
if ((*it)->_direction != SyncFileItem::Up) {
Expand All @@ -1177,8 +1178,41 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
(*it)->_errorString = tr("Ignored because of the \"choose what to sync\" blacklist");

if ((*it)->_isDirectory) {
auto it_base = it;
for (SyncFileItemVector::iterator it_next = it + 1; it_next != syncItems.end() && (*it_next)->_file.startsWith(path); ++it_next) {
it = it_next;
// We want to ignore almost all instructions for items inside selective-sync excluded folders.
//The exception are DOWN/REMOVE actions that remove local files and folders that are
//guaranteed to be up-to-date with their server copies.
if ((*it)->_direction == SyncFileItem::Down && (*it)->_instruction == CSYNC_INSTRUCTION_REMOVE) {
// We need to keep the "delete" items. So we need to un-ignore parent directories
QString parentDir = (*it)->_file;
do {
parentDir = QFileInfo(parentDir).path();
if (parentDir.isEmpty() || !parentDir.startsWith((*it_base)->destination())) {
break;
}
// Find the parent directory in the syncItems vector. Since the vector
// is sorted we can use a lower_bound, but we need a fake
// SyncFileItemPtr needle to compare against
if (!needle)
needle = SyncFileItemPtr::create();
needle->_file = parentDir;
auto parent_it = std::lower_bound(it_base, it, needle);
if (parent_it == syncItems.end() || (*parent_it)->destination() != parentDir) {
break;
}
ASSERT((*parent_it)->_isDirectory);
if ((*parent_it)->_instruction != CSYNC_INSTRUCTION_IGNORE) {
break; // already changed
}
(*parent_it)->_instruction = CSYNC_INSTRUCTION_UPDATE_METADATA;
(*parent_it)->_status = SyncFileItem::NoStatus;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay to keep _errorString set? I think some code considers finished items with a non-empty errorString an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing

(*parent_it)->_errorString.clear();

} while (true);
continue;
}
(*it)->_instruction = CSYNC_INSTRUCTION_IGNORE;
(*it)->_status = SyncFileItem::FileIgnored;
(*it)->_errorString = tr("Ignored because of the \"choose what to sync\" blacklist");
Expand Down
24 changes: 21 additions & 3 deletions test/testsyncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,18 @@ private slots:
FileInfo { QStringLiteral("parentFolder"), {
FileInfo{ QStringLiteral("subFolder"), {
{ QStringLiteral("fileA.txt"), 400 },
{ QStringLiteral("fileB.txt"), 400, 'o' }
{ QStringLiteral("fileB.txt"), 400, 'o' },
FileInfo { QStringLiteral("subsubFolder"), {
{ QStringLiteral("fileC.txt"), 400 },
{ QStringLiteral("fileD.txt"), 400, 'o' }
}},
FileInfo{ QStringLiteral("anotherFolder"), {
FileInfo { QStringLiteral("emptyFolder"), { } },
FileInfo { QStringLiteral("subsubFolder"), {
{ QStringLiteral("fileE.txt"), 400 },
{ QStringLiteral("fileF.txt"), 400, 'o' }
}}
}}
}}
}}
}}};
Expand All @@ -233,9 +244,11 @@ private slots:
{"parentFolder/subFolder/"});
fakeFolder.syncEngine().journal()->avoidReadFromDbOnNextSync("parentFolder/subFolder/");

// But touch a local file before the next sync, such that the local folder
// But touch local file before the next sync, such that the local folder
// can't be removed
fakeFolder.localModifier().setContents("parentFolder/subFolder/fileB.txt", 'n');
fakeFolder.localModifier().setContents("parentFolder/subFolder/subsubFolder/fileD.txt", 'n');
fakeFolder.localModifier().setContents("parentFolder/subFolder/anotherFolder/subsubFolder/fileF.txt", 'n');

// Several follow-up syncs don't change the state at all,
// in particular the remote state doesn't change and fileB.txt
Expand All @@ -250,8 +263,13 @@ private slots:
// The local state should still have subFolderA
auto local = fakeFolder.currentLocalState();
QVERIFY(local.find("parentFolder/subFolder"));
QVERIFY(local.find("parentFolder/subFolder/fileA.txt"));
QVERIFY(!local.find("parentFolder/subFolder/fileA.txt"));
QVERIFY(local.find("parentFolder/subFolder/fileB.txt"));
QVERIFY(!local.find("parentFolder/subFolder/subsubFolder/fileC.txt"));
QVERIFY(local.find("parentFolder/subFolder/subsubFolder/fileD.txt"));
QVERIFY(!local.find("parentFolder/subFolder/anotherFolder/subsubFolder/fileE.txt"));
QVERIFY(local.find("parentFolder/subFolder/anotherFolder/subsubFolder/fileF.txt"));
QVERIFY(!local.find("parentFolder/subFolder/anotherFolder/emptyFolder"));
}
}
}
Expand Down