Fix: Release the handles Files holds on a drive before ejecting it - #18906
Fix: Release the handles Files holds on a drive before ejecting it#18906Floral-Overcast wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The linked issue is not ready to be worked on, please read the contribution guidelines, ready to work on issues are at Files task board (view) |
| Ioc.Default.GetRequiredService<IStorageTrashBinService>().Watcher.StopWatcher(driveRoot); | ||
|
|
||
| // Give the released handles a moment to close before the shell issues the removal query | ||
| await Task.Delay(300); |
There was a problem hiding this comment.
It seems weird to have a Delay inside ReleaseDriveHandlesAsync. Can you move this delay to EjectDeviceAsync?
There was a problem hiding this comment.
The per-drive recycle-bin watcher is disposed and removed before the eject verb runs, but nothing recreates it. RecycleBinWatcher.StartWatcher() is only called by the watcher's constructor, and the app keeps the same singleton watcher. Consequently, this breaks recycle-bin notifications for that volume both when eject fails and when a successfully ejected volume is later reinserted, until Files restarts. Please add a lifecycle that re-arms monitoring when the volume remains/returns (and ensure it does not duplicate the still-active watchers for other volumes), or release this handle in a way that is paired with device removal/addition notifications.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Thanks for the review @hez2010 — both points addressed in de8e22a:
🤖 Generated with Claude Code |
|
This PR is generated by AI, closing. |
|
Hi, I'm a professional UX Designer attempting to implement this software into my workflow, just trying to add some basic functions I found missing in my own use of this software. I don't have a particular ownership or stake in whether or not this change is public, and I respect the process, but I was unaware I was breaking rules. Could you clarify what rules I broke or just where I could find them? |
You're not breaking any rules. For AI-generated PRs, we generally prefer contributions from people who are already familiar with the existing codebase, as that helps reduce the review burden. AI-generated PRs tend to contain subtle issues that can be difficult to identify and often require several rounds of changes before reaching a clean result. For example, the correct way of fixing the linked issue is to subscribe |
Resolved / Related Issues
Note: the issue isn't marked
Ready to build, but it's a confirmed, member-acknowledged bug ("I will keep this open to track Files blocking eject issue"), so I hope a concrete fix is useful. Happy to adjust the approach if the team prefers.Description
Ejecting a removable drive from Files frequently fails with Windows' "device is currently in use" dialog while ejecting the same drive from File Explorer works. The reason is that Files itself holds open handles on the volume and vetoes its own eject:
ReadDirectoryChangesWdirectory handle open (ShellViewModel.WatchForDirectoryChanges),FileSystemWatcher,RecycleBinWatcherarms a watcher on<drive>\$RECYCLE.BIN\<sid>for every non-network drive at startup and never releases it per-drive.DriveHelpers.EjectDeviceAsyncinvoked the shell "eject" verb without releasing any of these, so the PnP query-remove failed. (Explorer avoids this by releasing its handles onDBT_DEVICEQUERYREMOVE.)This PR makes
EjectDeviceAsyncrelease Files' own holds before invoking the verb:StopWatchingSubfoldersAndDescendants).RecycleBinWatcher.StopWatcher(driveRoot)overload).Not covered here (possible follow-ups): open preview-pane streams, in-flight size/search enumerations, and listening for
DBT_DEVICEQUERYREMOVEso ejects initiated outside Files also succeed — that last one is the structurally complete fix but a much larger change.Steps used to test these changes
🤖 Generated with Claude Code