-
Notifications
You must be signed in to change notification settings - Fork 972
fix: sync engine readonly folder file deletion #10226
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
Open
guruz
wants to merge
1
commit into
nextcloud:master
Choose a base branch
from
guruz:master_fix_7797
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+106
−8
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1637,6 +1637,14 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo( | |
| return; | ||
| } | ||
|
|
||
| // The move target is in a read-only folder so it can't be uploaded, but its data is safe | ||
| // at the source (restored below). Emitting remnantReadOnlyFolderDiscovered() schedules this | ||
| // local copy for deletion at the end of the sync, removing the duplicate. A genuinely new | ||
| // local file never reaches this move branch and is kept by checkPermissions (#7797/#10099). | ||
| if (!localEntry.isVirtualFile && item->_instruction == CSYNC_INSTRUCTION_IGNORE) { | ||
| emit _discoveryData->remnantReadOnlyFolderDiscovered(item); | ||
| } | ||
|
|
||
| // Here we know the new location can't be uploaded: must prevent the source delete. | ||
| // Two cases: either the source item was already processed or not. | ||
| auto wasDeletedOnClient = _discoveryData->findAndCancelDeletedJob(originalPath); | ||
|
|
@@ -2017,13 +2025,15 @@ bool ProcessDirectoryJob::checkPermissions(const OCC::SyncFileItemPtr &item) | |
| qCWarning(lcDisco) << "checkForPermission: Not allowed because you don't have permission to add subfolders to that folder:" << item->_file; | ||
| item->_instruction = CSYNC_INSTRUCTION_IGNORE; | ||
| item->_errorString = tr("Not allowed because you don't have permission to add subfolders to that folder"); | ||
| emit _discoveryData->remnantReadOnlyFolderDiscovered(item); | ||
| // Do NOT schedule the new local folder for deletion: it may contain data the user just | ||
| // created and that exists nowhere else. (see read-only folder regression, issues #7797/#10099). | ||
| return false; | ||
| } else if (!item->isDirectory() && !perms.hasPermission(RemotePermissions::CanAddFile)) { | ||
| qCWarning(lcDisco) << "checkForPermission: Not allowed because you don't have permission to add files in that folder:" << item->_file; | ||
| item->_instruction = CSYNC_INSTRUCTION_IGNORE; | ||
| item->_errorString = tr("Not allowed because you don't have permission to add files in that folder"); | ||
| emit _discoveryData->remnantReadOnlyFolderDiscovered(item); | ||
| // Do NOT schedule the new local file for deletion: it may be data the user just created | ||
| // and that exists nowhere else. (see read-only folder regression, issues #7797/#10099). | ||
|
Comment on lines
+2035
to
+2036
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same question (unless I miss something) |
||
| return false; | ||
| } | ||
| break; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-FileCopyrightText: 2018 ownCloud, Inc. | ||
|
|
@@ -297,9 +297,12 @@ | |
| currentLocalState = fakeFolder.currentLocalState(); | ||
|
|
||
| //6. | ||
| // The file should not exist on the remote, and not be there | ||
| QVERIFY(!currentLocalState.find("readonlyDirectory_PERM_MG_/newFile_PERM_GWDNV_.data")); | ||
| // The file cannot be uploaded to the read-only folder, but it MUST be kept locally: | ||
| // it is local-only data and silently deleting it would lose it (issues #7797/#10099). | ||
| QVERIFY(currentLocalState.find("readonlyDirectory_PERM_MG_/newFile_PERM_GWDNV_.data")); | ||
| QVERIFY(!fakeFolder.currentRemoteState().find("readonlyDirectory_PERM_MG_/newFile_PERM_GWDNV_.data")); | ||
| // Remove the kept local-only file so the following sections can compare local and remote. | ||
| removeReadOnly("readonlyDirectory_PERM_MG_/newFile_PERM_GWDNV_.data"); | ||
| // Both side should still be the same | ||
| QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); | ||
|
|
||
|
|
@@ -379,7 +382,8 @@ | |
| QVERIFY(currentLocalState.find("readonlyDirectory_PERM_MG_/subdir_PERM_CKG_" )); | ||
| // including contents | ||
| QVERIFY(currentLocalState.find("readonlyDirectory_PERM_MG_/subdir_PERM_CKG_/subsubdir_PERM_CKDNVG_/normalFile_PERM_GWVND_.data" )); | ||
| // new no longer exists | ||
| // new no longer exists: it was a move of an existing (server-side) item into a read-only | ||
| // folder, so the local copy is cleaned up while its data is restored at the source above. | ||
| QVERIFY(!currentLocalState.find("readonlyDirectory_PERM_MG_/newname_PERM_CK_/subsubdir_PERM_CKDNVG_/normalFile_PERM_GWVND_.data" )); | ||
| // but is not on server: should have been locally removed | ||
| QVERIFY(!currentLocalState.find("readonlyDirectory_PERM_MG_/newname_PERM_CK_")); | ||
|
|
@@ -561,6 +565,87 @@ | |
| QVERIFY(cls.find("zallowed/sub2/file")); | ||
| } | ||
|
|
||
| // A brand new local-only file dropped into a read-only folder cannot be uploaded. | ||
| // It must be ignored and kept on disk, not silently deleted, and a follow-up sync | ||
| // must be stable rather than looping (issues #7797/#10099). | ||
| void testNewLocalFileInReadOnlyFolderIsKept() | ||
| { | ||
| FakeFolder fakeFolder{FileInfo{}}; | ||
| auto &lm = fakeFolder.localModifier(); | ||
| auto &rm = fakeFolder.remoteModifier(); | ||
|
Comment on lines
+574
to
+575
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use longer name 🙏 |
||
| rm.mkdir("readonly"); | ||
| rm.insert("readonly/existing"); | ||
| // No CanAddFile ('C') and no CanAddSubDirectories ('K'): nothing new may be created here. | ||
| setAllPerm(rm.find("readonly"), RemotePermissions::fromServerString("GWDNV")); | ||
| QVERIFY(fakeFolder.syncOnce()); | ||
|
|
||
| // The user drops a new local-only file into the read-only folder. | ||
| lm.insert("readonly/newlocal", 42); | ||
|
|
||
| ItemCompletedSpy completeSpy(fakeFolder); | ||
| QVERIFY(fakeFolder.syncOnce()); | ||
|
|
||
| // It is a genuine new file (no remote counterpart) so it is ignored, never removed, | ||
| // and stays on disk. This is the move-branch's !isVirtualFile/IGNORE guard NOT firing. | ||
| QVERIFY(itemInstruction(completeSpy, "readonly/newlocal", CSYNC_INSTRUCTION_IGNORE)); | ||
| QVERIFY(fakeFolder.currentLocalState().find("readonly/newlocal")); | ||
| QVERIFY(!fakeFolder.currentRemoteState().find("readonly/newlocal")); | ||
|
|
||
| // The second sync must not loop: the file is still ignored+kept and no follow-up is requested. | ||
| completeSpy.clear(); | ||
| QVERIFY(fakeFolder.syncOnce()); | ||
| QVERIFY(itemInstruction(completeSpy, "readonly/newlocal", CSYNC_INSTRUCTION_IGNORE)); | ||
| QVERIFY(fakeFolder.currentLocalState().find("readonly/newlocal")); | ||
| QCOMPARE(fakeFolder.syncEngine().isAnotherSyncNeeded(), NoFollowUpSync); | ||
| } | ||
|
|
||
| // A synced file moved into a read-only folder cannot land at its new location. The duplicate | ||
| // copy in the read-only folder must be cleaned up, while the original is restored from the | ||
| // server with its content byte-intact - the rejected move must never destroy data (#7797/#10099). | ||
| void testMoveSyncedFileIntoReadOnlyFolderRestoresContent() | ||
| { | ||
| FakeFolder fakeFolder{FileInfo{}}; | ||
|
|
||
| // Discovery order decides whether the restore lands on the first or a follow-up sync; | ||
| // pin it so the test is deterministic. | ||
| auto syncOpts = fakeFolder.syncEngine().syncOptions(); | ||
| syncOpts._parallelNetworkJobs = 1; | ||
| fakeFolder.syncEngine().setSyncOptions(syncOpts); | ||
|
|
||
| auto &lm = fakeFolder.localModifier(); | ||
| auto &rm = fakeFolder.remoteModifier(); | ||
| rm.mkdir("allowed"); | ||
| rm.insert("allowed/file", 200, 'X'); // distinctive content to prove it survives | ||
| rm.mkdir("readonly"); | ||
| // No CanAddFile ('C') and no CanAddSubDirectories ('K'): nothing new may be created here. | ||
| setAllPerm(rm.find("readonly"), RemotePermissions::fromServerString("GWDNV")); | ||
| QVERIFY(fakeFolder.syncOnce()); | ||
|
|
||
| // The user moves an already-synced file into the read-only folder. | ||
| lm.rename("allowed/file", "readonly/file"); | ||
|
|
||
| QVERIFY(fakeFolder.syncOnce()); | ||
| // The forbidden-move restore can need a follow-up sync to settle. | ||
| if (fakeFolder.syncEngine().isAnotherSyncNeeded() == ImmediateFollowUp) { | ||
| QVERIFY(fakeFolder.syncOnce()); | ||
| } | ||
|
|
||
| // The duplicate in the read-only folder is cleaned up locally and never reaches the server. | ||
| QVERIFY(!fakeFolder.currentLocalState().find("readonly/file")); | ||
| QVERIFY(!fakeFolder.currentRemoteState().find("readonly/file")); | ||
|
|
||
| // The original is restored with its content intact (size and bytes), not just its path. | ||
| auto localState = fakeFolder.currentLocalState(); | ||
| auto *restored = localState.find("allowed/file"); | ||
| QVERIFY(restored); | ||
| QCOMPARE(restored->size, qint64{200}); | ||
| QCOMPARE(restored->contentChar, 'X'); | ||
|
|
||
| // Local and remote agree on everything, content included, and the sync has settled. | ||
| QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); | ||
| QCOMPARE(fakeFolder.syncEngine().isAnotherSyncNeeded(), NoFollowUpSync); | ||
| } | ||
|
|
||
| void testParentMoveNotAllowedChildrenRestored() | ||
| { | ||
| FakeFolder fakeFolder{FileInfo{}}; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not this folder be read-only ?
I guess users can override the permissions and better be safe than sorry