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.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
Same-drive moves: one rename thread, one shell note per folder (674)
gelenmedyab38df881cfae
diff --git a/crates/rf-win/examples/move_many.rs b/crates/rf-win/examples/move_many.rsnew file mode 100644index 00000000..1fa83ddd--- /dev/null+++ b/crates/rf-win/examples/move_many.rs@@ -0,0 +1,52 @@+//! Times a same-drive move of many small files into a subfolder of a big folder, through the+//! fast engine and with a plain loop of renames, without the window around it.+//! `cargo run --release -p rf-win --example move_many -- <scratch dir> [files to move] [other files]`++use std::path::PathBuf;+use std::sync::Arc;+use std::sync::atomic::AtomicBool;+use std::time::Instant;++use rf_win::fileops::{Tracker, Transfer};++fn main() {+ let mut args = std::env::args().skip(1);+ let root = PathBuf::from(args.next().expect("scratch dir"));+ let moved: usize = args.next().and_then(|a| a.parse().ok()).unwrap_or(10_000);+ let others: usize = args.next().and_then(|a| a.parse().ok()).unwrap_or(50_000);+ for engine in ["raw", "fast"] {+ let big = root.join(format!("big-{engine}"));+ let _ = std::fs::remove_dir_all(&big);+ std::fs::create_dir_all(&big).unwrap();+ for i in 0..400 {+ std::fs::create_dir(big.join(format!("sub {i:03}"))).unwrap();+ }+ for i in 0..others {+ std::fs::write(big.join(format!("other {i:06}.png")), [0u8; 512]).unwrap();+ }+ let mut sources = Vec::with_capacity(moved);+ for i in 0..moved {+ let p = big.join(format!("pic {i:06}.png"));+ std::fs::write(&p, [0u8; 512]).unwrap();+ sources.push(p);+ }+ let dest = big.join("target");+ std::fs::create_dir(&dest).unwrap();+ let tracker = Arc::new(Tracker::new(Box::new(|_, _, _| {}), Arc::new(AtomicBool::new(false))));+ let t = Instant::now();+ let ok = match engine {+ "fast" => rf_win::fastcopy::transfer(Transfer::Move, &sources, &dest, tracker).unwrap(),+ "raw" => {+ let _ = tracker;+ for s in &sources {+ std::fs::rename(s, dest.join(s.file_name().unwrap())).unwrap();+ }+ true+ }+ _ => rf_win::fileops::transfer_tracked(Transfer::Move, &sources, &dest, tracker).unwrap(),+ };+ let n = std::fs::read_dir(&dest).unwrap().count();+ println!("{engine}: moved {n}/{moved} in {:.2} s (ok {ok})", t.elapsed().as_secs_f64());+ let _ = std::fs::remove_dir_all(&big);+ }+}diff --git a/crates/rf-win/src/fastcopy.rs b/crates/rf-win/src/fastcopy.rsindex fd5e56cf..feba7c8a 100644--- a/crates/rf-win/src/fastcopy.rs+++ b/crates/rf-win/src/fastcopy.rs@@ -756,6 +756,19 @@ fn run_jobs(mut p: Plan, tracker: &Tracker, threads: usize, journal: Option<(&JrOutcome { undo: p.undo, failed, whole: p.whole, copied, src_dirs: p.src_dirs, cancelled }}+/// Tells the shell once about each folder a transfer changed: the sources' folders, then the destination. Once per folder, not per+/// item: every call costs the shell a look at the folder, about 9 ms in one of 50,000 files, which made the notes of a 2,000-file move+/// take 18 s.+fn notify_folders<'a>(parents: impl Iterator<Item = &'a Path>, dest_dir: &Path) {+ let mut seen: HashSet<&Path> = HashSet::new();+ for p in parents {+ if p != dest_dir && seen.insert(p) {+ crate::shell::notify_updated(p);+ }+ }+ crate::shell::notify_updated(dest_dir);+}+/// Copies `sources` into `dest_dir` in parallel (conflicts as `tracker.ask` says; without it/// both are kept). Returns the undo pairs and the leftovers for the shell.pub fn copy(sources: &[PathBuf], dest_dir: &Path, tracker: &Tracker, threads: usize) -> Outcome {@@ -779,7 +792,9 @@ pub fn transfer(kind: Transfer, sources: &[PathBuf], dest_dir: &Path, tracker: Alet (here, there): (Vec<PathBuf>, Vec<PathBuf>) = sources.iter().cloned().partition(|s| kind == Transfer::Move && same_volume(s, dest_dir));let mut ok = true;if !here.is_empty() {- let (out, jr) = execute(Transfer::Move, &here, dest_dir, &tracker, 4, true);+ // one thread: renames into one folder from several threads at once wait on each other in NTFS (2,000 files from a folder+ // of 50,000 into its subfolder: 42.7 s on 4 threads, 0.59 s on 1, where a plain loop of renames takes 0.61 s)+ let (out, jr) = execute(Transfer::Move, &here, dest_dir, &tracker, 1, true);let r = finish(Transfer::Move, &here, dest_dir, &tracker, out);if let Some(j) = jr {j.close();@@ -795,12 +810,7 @@ pub fn transfer(kind: Transfer, sources: &[PathBuf], dest_dir: &Path, tracker: A}ok &= r?;}- for s in sources {- if let Some(p) = s.parent() {- crate::shell::notify_updated(p);- }- }- crate::shell::notify_updated(dest_dir);+ notify_folders(sources.iter().filter_map(|s| s.parent()), dest_dir);Ok(ok && !tracker.cancel.load(Ordering::Relaxed))}@@ -1123,12 +1133,7 @@ pub fn resume(journal: &Path, tracker: Arc<Tracker>) -> anyhow::Result<bool> {let r = finish(kind, &l.info.sources, &l.info.dest, &tracker, out);// done, failed or cancelled by the user: either way nothing is left to resumejr.close();- for s in &l.info.sources {- if let Some(p) = s.parent() {- crate::shell::notify_updated(p);- }- }- crate::shell::notify_updated(&l.info.dest);+ notify_folders(l.info.sources.iter().filter_map(|s| s.parent()), &l.info.dest);r}