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 folder's size follows a delete or paste inside it without F5 (965)

denfry7b851c9510ac
diff --git a/crates/rf-app/src/folder_view.rs b/crates/rf-app/src/folder_view.rs
index 6179d028..c1774ab2 100644
--- a/crates/rf-app/src/folder_view.rs
+++ b/crates/rf-app/src/folder_view.rs
@@ -1898,6 +1898,18 @@ impl FolderView {
/// network drive or in a WSL distribution, or its watcher could not be started. (FTP is left out: what goes there reads the
/// server again itself.) The side columns of the columns layout have no watcher at all.
pub(crate) fn reread_touched(&mut self, touched: &rf_core::touched::Touched, cx: &mut Context<Self>) {
+ // A folder's size covers everything under it, and its parent's change notices say nothing of what happens inside it: after a
+ // deletion or a paste inside a folder of this list, its size stayed as it was until F5 (issue 965). Those folders are
+ // measured again, as F5 does, not forgotten.
+ let stale: Vec<PathBuf> = self.folder_sizes.keys().filter(|d| touched.inside(d)).cloned().collect();
+ if !stale.is_empty() {
+ for d in stale {
+ self.folder_sizes.remove(&d);
+ rf_win::foldersize::shared_cache().invalidate(&d);
+ self.folder_size(d, cx);
+ }
+ cx.notify();
+ }
let columns = self.column_cache.len();
self.column_cache.retain(|dir, _| touched.changed(dir).is_none());
if self.column_cache.len() != columns {
diff --git a/crates/rf-core/src/touched.rs b/crates/rf-core/src/touched.rs
index 0fddc5d1..a1041e28 100644
--- a/crates/rf-core/src/touched.rs
+++ b/crates/rf-core/src/touched.rs
@@ -122,6 +122,15 @@ impl Touched {
}
}
+ /// Whether anything in or under `dir` may have changed: its own list, or a folder anywhere inside it. That is what a size measured
+ /// for `dir` covers (issue 965: a folder's size in its parent's list stayed as it was after files were deleted inside it, since
+ /// the parent's change notices say nothing of what happens inside a subfolder).
+ pub fn inside(&self, dir: &Path) -> bool {
+ let at = self.mapped.key(dir);
+ let below = format!("{}\\", at.trim_end_matches('\\'));
+ self.dirs.keys().chain(self.trees.keys()).any(|k| *k == at || k.starts_with(&below))
+ }
+
/// The folders with a changed list that are on a drive whose change notices can't be relied on, in every spelling they may be
/// open under.
pub fn remote_dirs(&self) -> Vec<PathBuf> {
@@ -160,6 +169,20 @@ mod tests {
assert_eq!(t.remote_dirs(), paths(&[r"\\wsl.localhost\ubuntu\home\me", r"\\wsl$\ubuntu\home\me"]));
}
+ #[test]
+ fn a_change_anywhere_inside_a_folder_is_inside_it_and_nowhere_else() {
+ let t = Touched::by_delete(&paths(&[r"C:\top\data\sub\g.bin"]), Mapped::default(), unc);
+ assert!(t.inside(Path::new(r"C:\top\data\sub")), "the folder the item was deleted from");
+ assert!(t.inside(Path::new(r"C:\top\data")), "a folder above it");
+ assert!(t.inside(Path::new(r"C:\")), "the drive");
+ assert!(t.inside(Path::new(r"c:\TOP\")), "case and a closing separator");
+ assert!(!t.inside(Path::new(r"C:\top\database")), "a name that only begins the same");
+ assert!(!t.inside(Path::new(r"C:\top\data\other")), "a folder beside it");
+ let m = Touched::by_transfer(false, &paths(&[r"D:\a.txt"]), Path::new(r"C:\top\in"), Mapped::default(), unc);
+ assert!(m.inside(Path::new(r"C:\top")), "a paste into a folder inside it");
+ assert!(!m.inside(Path::new(r"D:\")), "a copy changes nothing where it takes from");
+ }
+
#[test]
fn a_copy_leaves_the_folder_it_takes_from_alone() {
let t = Touched::by_transfer(false, &paths(&[r"\\nas\share\a.txt"]), Path::new(r"\\nas\in"), Mapped::default(), unc);