From dcbe7873cda5637b9d6b6999bf9dcfd098a05ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Sun, 6 Oct 2024 13:04:52 +0800 Subject: [PATCH] fix: upserting operation should handle deleting in edge cases where the source and target URNs are different (#1737) --- yazi-fs/src/files.rs | 4 ++++ yazi-shared/src/fs/op.rs | 11 +++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/yazi-fs/src/files.rs b/yazi-fs/src/files.rs index 944b8c51..fc38f0b6 100644 --- a/yazi-fs/src/files.rs +++ b/yazi-fs/src/files.rs @@ -301,6 +301,10 @@ impl Files { return; } + self.update_deleting( + files.iter().filter(|&(u, f)| u != f.urn()).map(|(_, f)| f.urn_owned()).collect(), + ); + let (hidden, items) = self.update_updating(files); if hidden.is_empty() && items.is_empty() { return; diff --git a/yazi-shared/src/fs/op.rs b/yazi-shared/src/fs/op.rs index 98a2b54e..13b1543c 100644 --- a/yazi-shared/src/fs/op.rs +++ b/yazi-shared/src/fs/op.rs @@ -48,15 +48,14 @@ impl FilesOp { } pub fn rename(map: HashMap) { - let mut parents = HashMap::new(); + let mut parents: HashMap<_, (HashSet<_>, HashMap<_, _>)> = Default::default(); for (o, n) in map { let Some(o_p) = o.parent_url() else { continue }; - if o == n.url { - parents.entry(o_p).or_insert((HashSet::new(), HashMap::new())).1.insert(o.urn_owned(), n); - } else if let Some(n_p) = n.url.parent_url() { - parents.entry(o_p).or_insert((HashSet::new(), HashMap::new())).0.insert(o.urn_owned()); - parents.entry(n_p).or_insert((HashSet::new(), HashMap::new())).1.insert(n.urn_owned(), n); + let Some(n_p) = n.url.parent_url() else { continue }; + if o_p != n_p { + parents.entry(o_p).or_default().0.insert(o.urn_owned()); } + parents.entry(n_p).or_default().1.insert(n.urn_owned(), n); } for (p, (o, n)) in parents { match (o.is_empty(), n.is_empty()) {