Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

Bin folders of USB and SD disks are not watched, so they can be ejected (622)

gelenmedya82c464d523c3
diff --git a/crates/rf-win/src/desktop/binwatch.rs b/crates/rf-win/src/desktop/binwatch.rs
index 4b1d9d57..ea5babfa 100644
--- a/crates/rf-win/src/desktop/binwatch.rs
+++ b/crates/rf-win/src/desktop/binwatch.rs
@@ -23,12 +23,23 @@ pub fn bin_dirs(letters: &[char], sid: &str) -> Vec<PathBuf> {
letters.iter().map(|l| PathBuf::from(format!("{l}:\\$Recycle.Bin\\{sid}"))).collect()
}
-/// The bin folders of this user on the fixed disks that have one.
+/// Whether a disk of this kind can be pulled out: a watch held open on it would stop "Safely remove" / eject.
+pub fn pluggable(bus: Option<crate::drives::Bus>, removable: bool) -> bool {
+ use crate::drives::Bus;
+ removable || matches!(bus, Some(Bus::Usb | Bus::Sd))
+}
+
+/// The bin folders of this user on the fixed disks that have one. A USB or SD disk that Windows counts as fixed is left out: the
+/// desktop and the dock held its bin folder open, so ejecting it failed with "in use" while no window showed it (issue 622).
pub fn existing_bin_dirs() -> Vec<PathBuf> {
let Some(sid) = crate::dock::startuser::current_sid() else { return Vec::new() };
let letters = fixed_letters(unsafe { GetLogicalDrives() }, |c| {
let root: Vec<u16> = format!("{c}:\\").encode_utf16().chain(std::iter::once(0)).collect();
- unsafe { GetDriveTypeW(PCWSTR(root.as_ptr())) == 3 }
+ if unsafe { GetDriveTypeW(PCWSTR(root.as_ptr())) } != 3 {
+ return false;
+ }
+ let disk = crate::drives::disk_info(std::path::Path::new(&format!("{c}:\\")));
+ !pluggable(disk.bus, disk.removable)
});
bin_dirs(&letters, &sid).into_iter().filter(|d| d.is_dir()).collect()
}
@@ -37,6 +48,17 @@ pub fn existing_bin_dirs() -> Vec<PathBuf> {
mod tests {
use super::*;
+ #[test]
+ fn a_usb_or_sd_disk_is_pluggable_an_internal_one_is_not() {
+ use crate::drives::Bus;
+ assert!(pluggable(Some(Bus::Usb), false), "a USB disk Windows counts as fixed");
+ assert!(pluggable(Some(Bus::Sd), false));
+ assert!(pluggable(None, true), "a disk that says it is removable");
+ assert!(!pluggable(Some(Bus::Nvme), false));
+ assert!(!pluggable(Some(Bus::Sata), false));
+ assert!(!pluggable(None, false), "nothing known: watched as before");
+ }
+
#[test]
fn letters_come_from_the_mask_and_only_fixed_ones_stay() {
// C, D and F present; D is a USB stick