Repository navigation
Keep local items whose stat fails instead of deleting them. - #11359
Conversation
|
/backport to stable-35.0 |
i2h3
left a comment
There was a problem hiding this comment.
I cannot test on Windows and I am not familiar with the classic sync engine in depth. So take these agent findings with a grain of salt for your consideration. I intentionally did not review with a request for changes.
-
Unreadable files are still deleted on the server on some file systems (
src/libsync/discoveryphase.cpp:L381-383,src/csync/vio/csync_vio_local_unix.cpp:L84-109)- What this is: On Linux and macOS,
csync_vio_local_readdir()first takes the file type from the directory listing (d_type). Then it callslstat(), which asks the OS for size, time and file ID, andDiscoverySingleLocalDirectoryJob::run()drops every entry whose type is stillItemTypeSkip. - Problem: Some file systems leave
d_typeasDT_UNKNOWN, for example XFS made withftype=0and some network mounts, and readdir(3) says apps must handle that. There a failedlstat()leaves the type atItemTypeSkip, so the entry is dropped before anyone readsis_stat_error, and the server copy is deleted just like before this PR. - Fix: Keep entries with a stat error:
if (dirent->type == ItemTypeSkip && !dirent->is_stat_error) continue;. The new branch inprocessFileAnalyzeLocalInfo()then ignores them. - If skipped: The bug this PR fixes stays open for everyone whose sync folder is on such a file system.
- What this is: On Linux and macOS,
-
A folder deleted on the server still takes the unreadable file with it (
src/libsync/discovery.cpp:L1388-1394)- What this is: Discovery is the step that compares local files, server files and the sync database and decides what to do. When it ignores a child it sets
_childIgnored = true, andprocessSubJobs()(L2410) then turns aREMOVEof the parent folder intoNONE. - Problem: The new branch does not set this flag. Example: someone deletes
Project/on the server whileProject/draft.docxcannot be read here, soProject/staysREMOVE, the propagator (the part that carries out the decisions) skips ignored items inside a removed folder (owncloudpropagator.cpp:L573), andPropagateLocalRemovedeletes the whole folder withdraft.docxin it. - Fix: Add
_childIgnored = true;to the branch, likehandleExcluded()(L516) andprocessBlacklisted()(L2171) do. In the Unix test, removesubon the server before the second sync and check withItemCompletedSpythatsubdoes not complete asREMOVE. - If skipped: Edits in that file that were not uploaded yet are lost with the folder. Stopping that kind of loss is the point of this PR.
- What this is: Discovery is the step that compares local files, server files and the sync database and decides what to do. When it ignores a child it sets
-
"It will be checked again on a later sync" is not true for most syncs (
src/libsync/discovery.cpp:L1389-1391)- What this is: When the file watcher works, most syncs only scan the local paths on the
LocalDiscoveryTrackerlist (paths that changed or failed last time) and read everything else from the database. A full local scan runs once an hour by default (ConfigFile::fullLocalDiscoveryInterval()). - Problem:
LocalDiscoveryTracker::slotItemCompleted()countsFileIgnoredas a success and drops the path from that list. So the next sync reads the file from the database, and an edit made while stat failed waits for the hourly scan or for the next write to that file. - Fix: Set
SyncFileItem::SoftErrorinstead ofFileIgnored, like the "open in editor" case atL1357. A soft error puts the path back on the list, andblacklistUpdate()does not blacklist it because it has no HTTP code. - If skipped: With the short-lived Windows errors from the PR description, an edit can stay only on this computer for up to an hour.
- What this is: When the file watcher works, most syncs only scan the local paths on the
-
The Windows test most likely passes without the fix (
test/testlocaldiscovery.cpp:L106-114)- What this is: The test denies "read attributes" (
RA) ona.txtwithicacls, so thatcsync_vio_local_stat()should fail. - Problem: The PR description says only
/deny (S)reproduced the bug. I think the reason is that NTFS still grants read attributes on a file to anyone who may list its folder, andCreateFileWwith access0only asks for that plusSYNCHRONIZE, so the open works, stat succeeds and the new code never runs. - Fix: Deny
(S)as in the manual test. Revert the twocsync_vio_local_*.cpplines once and confirm the test fails. - If skipped: Windows, where the bug was reported, has no test that fails when the fix breaks.
- What this is: The test denies "read attributes" (
2ec2f58 to
9fabdc4
Compare
20465bc to
e53675c
Compare
9fd03de to
175a3f3
Compare
There was a problem hiding this comment.
It is your call which to consider.
Must change
-
Subfolders of an unreadable folder are deleted on the server (
src/libsync/discovery.cpp:L1388-1395)- What this is: For an item whose stat failed, the new branch calls
finalize(), which walks into folders.ItemTypeSkipErrorhasisDirectory == false, so the walk usesParentDontExist, which means "this folder no longer exists on this computer". - Problem: Inside that walk every synced child looks deleted here and gets
REMOVEtoward the server. Files survive because the folder's ignore job fails and cancels them, but a subfolderREMOVEgoes to the root's folder deletion list (owncloudpropagator.cpp:L650-654), which still runs after aSoftError(L1717-1750). - Fix: Replace
finalize();withQ_EMIT _discoveryData->itemDiscovered(item);, like the VFS suffix ignore atL652-660, so nothing below the unreadable item is touched this sync. Test it in the Unix test:mkdir("sub/inner/deep"), addsub/inner/deep/c.txt, sync, setsubtoReadOwner, sync, and check thatsub/inner/deep/c.txtis still on the server before the recovery sync, because the recovery sync uploads it again and hides the loss. - If skipped: Every folder one level below an unreadable folder goes to the server trash and is removed from all other devices.
- What this is: For an item whose stat failed, the new branch calls
-
An unreadable placeholder still deletes its file on the server with suffix VFS (
src/csync/vio/csync_vio_local_unix.cpp:L107-110,src/libsync/discovery.cpp:L152-155)- What this is: Suffix VFS keeps virtual files as
name.nextcloudstubs and is used outside Windows when OpenVFS is not available.process()moves the local entryfoo.nextcloudontofooso it matches the database and server entries, but only whenisVirtualFileis true, whichVfsSuffix::statTypeVirtualFile()sets from the name. - Problem: The new early
returnskips that call whenlstat()fails, sofoohas no local entry, getsREMOVEtoward the server, and the server copy offoois deleted. On master the call still ran after a failed stat, so this is new. - Fix: Also move error entries that carry the suffix:
if (!e.isVirtualFile && !(e.type == ItemTypeSkipError && hasVirtualFileSuffix(e.name))) continue;. The new branch then ignoresfoo. Add a case totest/testsyncvirtualfiles.cpp: a dehydrated placeholder in a folder set toReadOwner, sync, and check that the server file still exists. - If skipped: Suffix VFS users lose a server file whenever its placeholder can't be read, which is the bug this PR sets out to fix.
- What this is: Suffix VFS keeps virtual files as
-
The Windows test comment contradicts the test (
test/testlocaldiscovery.cpp:L125)- What this is: The comment says a zero-access open "skips the DACL check", which is the check against the file's permission list.
- Problem: If that check were skipped, denying
Swould make no difference either, so the comment gives the wrong reason. - Fix:
// Denying SYNCHRONIZE makes the open in csync_vio_local_stat() fail. Denying read attributes does not. - If skipped: The next person who changes this test starts from a wrong idea.
-
Part of a test check can never be true (
test/testlocaldiscovery.cpp:L107)- What this is:
QVERIFY(!subItem || subItem->_instruction != CSYNC_INSTRUCTION_REMOVE); - Problem:
ItemCompletedSpy::findItem()returns a new empty item when nothing matches and never returns null (test/syncenginetestutils.cpp:L1590), so!subItemis always false. - Fix:
QVERIFY(completeSpy.findItem("sub")->_instruction != CSYNC_INSTRUCTION_REMOVE); - If skipped: Readers think a missing item is a special case here.
- What this is:
The four points from my last review are fixed.
Report items whose stat fails as ItemTypeSkipError and pass them up to discovery. The parent is marked child ignored and the item is retried via SoftError. Assisted-by: ClaudeCode:claude-sonnet-5-5 Signed-off-by: Camila Ayres <hello@camilasan.com>
Signed-off-by: Camila Ayres <hello@camilasan.com>
Emit the unreadable item directly so subfolders are not removed on the server. Move suffixed error entries onto the unsuffixed name so suffix VFS placeholders keep their server file. Assisted-by: ClaudeCode:claude-sonnet-5-5 Signed-off-by: Camila Ayres <hello@camilasan.com>
9489b00 to
19d5e91
Compare
There was a problem hiding this comment.
-
A new local file can be deleted for good when the server deletes its folder (
src/libsync/discovery.cpp:L1389,L2411-2414,L2715-2720)- What this is: When the server deletes
sub, a local file in it that was never uploaded getsREMOVEwith "move to trash" fromcheckNewDeleteConflict(). That wish only works inside a folder delete, because outside Windows cfapi a singlePropagateLocalRemoveignores it (propagatorjobs.cpp:L171-174). - Problem: If
subalso holds an unreadablea.txt, the new_childIgnored = trueturns the folder delete intoNONE, sonew.txtis removed on its own withFileSystem::remove()and never reaches the trash. Locked and excluded siblings (L516) already cause this on master, and this PR adds one more trigger, which I asked for in my first review. - Fix: Open a ticket instead of growing this PR. When
processSubJobs()turns a folderREMOVEintoNONE, it should also turn thecheckNewDeleteConflict()items inside that folder intoIGNORE. - If skipped: A file that exists nowhere else is deleted without a trash copy. It needs an unreadable file, a new file and a server-side folder delete at the same time, so it is rare.
- What this is: When the server deletes
-
The "parent removal must not become a local removal" promise holds only one level deep (
test/testlocaldiscovery.cpp:L100,src/libsync/discovery.cpp:L2130-2141,src/libsync/owncloudpropagator.cpp:L573)- What this is: The test checks that deleting
subon the server keepssub/a.txtwhena.txtcan't be read. That works because_childIgnoredturns theREMOVEofsubintoNONE. - Problem: If the server deletes
Pand the unreadable file isP/sub/a.txt,subruns in a separate deleted-folder job that never reports_childIgnoredback toP, soPis still removed recursively and the propagator (the part that carries out the decisions) just skips the ignored child. The same happens in a partial scan, where a sync only re-reads changed folders anda.txtcomes from the database without being read. - Fix: Track it in the same ticket. One idea: in
OwncloudPropagator::start(), when anIGNOREitem with an error status lies insideremovedDirectory, drop that folder's delete job instead of skipping the item. - If skipped: On Linux and macOS the delete fails on every sync because the folder can't be searched. On Windows the unreadable file is probably deleted with its folder, which I could not check.
- What this is: The test checks that deleting
-
The suffix VFS test passes without the fix (
test/testsyncvirtualfiles.cpp:L132,L140)- What this is:
testUnreadablePlaceholderKeepsServerFileis meant to prove that an unreadableA/a1.nextcloudkeepsA/a1on the server. - Problem:
setLocalDiscoveryOptions(LocalDiscoveryStyle::DatabaseAndFilesystem)with no paths turns off local scanning for every folder, and it is the same call the "skip local discovery" row uses atL164. SoAis never read,lstat()never fails and the test also passes on master, whilefindItem("A/a1")misses aREMOVEanyway because that is reported asA/a1.nextcloud. - Fix: Delete
L132. ReplaceL140withQCOMPARE(completeSpy.findItem("A/a1")->_instruction, CSYNC_INSTRUCTION_IGNORE);, which only passes when the re-keying moved the item. - If skipped: The suffix VFS fix from this round has no test that fails when it breaks.
- What this is:
-
An unreadable leftover stub is reported under the readable file's name (
src/libsync/discovery.cpp:L168-172)- What this is: With suffix VFS the re-keying loop now also takes unreadable
foo.nextcloudentries. When a readablefooexists as well, thenameOverridebranch processes the stub under the namefoo. - Problem: The "Could not read local file" error then names
foo, which is the readable file. The soft error can also wipe the error blacklist entry (the retry back-off record) offoo. - Fix: Keep the override for real placeholders only:
} else if (!hasOtherData && e.isVirtualFile) {. The stub then keeps its own name, as in the previous round. - If skipped: Users see an error for the wrong file, and a failing upload of
fooloses its back-off. Both names must exist locally for this, so it is rare.
- What this is: With suffix VFS the re-keying loop now also takes unreadable
Verdict: fix 3 and 4 first. 1 and 2 can go to a ticket.
✅ |
Make the suffix VFS regression test scan the folder locally so it fails without the fix. Assisted-by: ClaudeCode:claude-sonnet-5-5 Signed-off-by: Camila Ayres <hello@camilasan.com>
91d47ca to
bc619e4
Compare
i2h3
left a comment
There was a problem hiding this comment.
I did another review round and it yielded no more findings except the already brought up missing commit signature. 🙂
|
|
/backport to stable-34.0 please |




Resolves
A failed stat on an existing local file was dropped from discovery and then propagated as a remote delete, so the server trashed the file.
Errors found in the logs (Windows):
"WindowsError: -7fe0fffb: An invalid name request was made. The name requested cannot be retrieved at this time.""WindowsError: -7ff8fe7a: The operation is only supported on files under a cloud sync root."Summary
The item is kept and flagged with is_stat_error so discovery ignores it for that sync.
To test this (Windows)
I was only able to test this by quitting the client and then running:
icacls "E:\Nextcloud\TestFolder\test.txt" /deny "<username>:(S)"Start the client again and then the ignore instruction will be in the logs:
Checklist
AI (if applicable)