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.

A cloud folder registered twice is listed once (987)

gelenmedya30cac96fcc98
diff --git a/crates/rf-app/src/places.rs b/crates/rf-app/src/places.rs
index 633509ef..0900d958 100644
--- a/crates/rf-app/src/places.rs
+++ b/crates/rf-app/src/places.rs
@@ -328,13 +328,26 @@ fn same_recent(a: &[Recent], b: &[Recent]) -> bool {
a.len() == b.len() && a.iter().zip(b).all(|(x, y)| x.target == y.target && x.used_ms == y.used_ms && x.is_dir == y.is_dir)
}
+/// Whether two paths name the same folder, whatever the letters' case and a trailing separator. Pure.
+fn same_folder(a: &std::path::Path, b: &std::path::Path) -> bool {
+ let plain = |p: &std::path::Path| p.to_string_lossy().trim_end_matches(['\\', '/']).to_lowercase();
+ plain(a) == plain(b)
+}
+
/// Cloud folders (OneDrive, Dropbox, iCloud, Google Drive) and WSL distributions.
fn load_cloud_and_wsl() -> Vec<Pinned> {
let mut out = Vec::new();
let mut add = |title: String, path: PathBuf, icon: L| {
- let same = |p: &Pinned| p.path.as_os_str().eq_ignore_ascii_case(path.as_os_str());
- if path.is_dir() && !out.iter().any(same) {
- out.push(Pinned { title, path, icon });
+ // (one folder written two ways is one row: issue 987, Nextcloud registers each account twice, once with a trailing
+ // separator; both rows were listed and both lit up when one was open)
+ if !path.is_dir() {
+ return;
+ }
+ match out.iter_mut().find(|p: &&mut Pinned| same_folder(&p.path, &path)) {
+ // (the longer name says more: "Nextcloud - cloud.example.com - User" over a bare "Nextcloud")
+ Some(known) if title.chars().count() > known.title.chars().count() => known.title = title,
+ Some(_) => {}
+ None => out.push(Pinned { title, path, icon }),
}
};
for (var, title) in [("OneDriveConsumer", "OneDrive"), ("OneDriveCommercial", "OneDrive (İş)"), ("OneDrive", "OneDrive")] {
@@ -726,6 +739,19 @@ pub fn pins_follow(cx: &mut App, from: &std::path::Path, to: Option<&std::path::
}
}
+#[cfg(test)]
+mod cloud_row_tests {
+ use super::same_folder;
+ use std::path::Path;
+
+ /// Issue 987: Nextcloud writes one folder with and without a trailing separator; it is one folder.
+ #[test]
+ fn one_folder_written_two_ways_is_one_folder() {
+ assert!(same_folder(Path::new(r"C:\Users\me\NextcloudB\"), Path::new(r"c:\users\me\NextcloudB")));
+ assert!(!same_folder(Path::new(r"C:\Users\me\NextcloudA"), Path::new(r"C:\Users\me\NextcloudB")));
+ }
+}
+
#[cfg(test)]
mod recent_merge_tests {
use super::{Recent, merge_recent};