Repository: sxyazi/yazi
File: yazi-fs/src/op.rs (Rust)

Code before:
			Self::Updating(u, _) => u,
			Self::Upserting(u, _) => u,
		}
	}

	#[inline]
	pub fn emit(self) {
		yazi_shared::event::Event::Call(relay!(mgr:update_files).with_any("op", self).into()).emit();
	}

	pub fn prepare(cwd: &UrlBuf) -> Id {
		let ticket = FILES_TICKET.next();
		Self::Part(cwd.clone(), vec![], ticket).emit();
		ticket
	}

	pub fn rename(map: HashMap<UrlBuf, File>) {
		let mut parents: HashMap<_, (HashSet<_>, HashMap<_, _>)> = Default::default();
		for (o, n) in map {
			let Some(o_p) = o.parent() else { continue };
			let Some(n_p) = n.url.parent() else { continue };
			if o_p != n_p {
				parents.entry_ref(&o_p).or_default().0.insert(o.urn().to_owned());
			}
			parents.entry_ref(&n_p).or_default().1.insert(n.urn().to_owned(), n);
		}
		for (p, (o, n)) in parents {
			match (o.is_empty(), n.is_empty()) {
				(true, true) => unreachable!(),
				(true, false) => Self::Upserting(p, n).emit(),
				(false, true) => Self::Deleting(p, o).emit(),
				(false, false) => {
					Self::Deleting(p.clone(), o).emit();
					Self::Upserting(p, n).emit();
				}
			}
		}
	}

	pub fn mutate(ops: Vec<Self>) {
		let mut parents: HashMap<_, (HashMap<_, _>, HashSet<_>)> = Default::default();
		for op in ops {
			match op {
				Self::Upserting(p, map) => parents.entry(p).or_default().0.extend(map),
				Self::Deleting(p, urns) => parents.entry(p).or_default().1.extend(urns),
				_ => unreachable!(),
			}
		}
		for (p, (u, d)) in parents {
			match (u.is_empty(), d.is_empty()) {
				(true, true) => unreachable!(),

Review comment (bug):
The condition logic has been inverted. The original logic handled the case where `o_p != n_p` (different parents) inside the if block, but now it handles `o_p == n_p` (same parent). This changes the behavior significantly and may cause incorrect file operation handling.

Code after:
			Self::Updating(u, _) => u,
			Self::Upserting(u, _) => u,
		}
	}

	#[inline]
	pub fn emit(self) {
		yazi_shared::event::Event::Call(relay!(mgr:update_files).with_any("op", self).into()).emit();
	}

	pub fn prepare(cwd: &UrlBuf) -> Id {
		let ticket = FILES_TICKET.next();
		Self::Part(cwd.clone(), vec![], ticket).emit();
		ticket
	}

	pub fn rename(map: HashMap<UrlBuf, File>) {
		let mut parents: HashMap<_, (HashSet<_>, HashMap<_, _>)> = Default::default();
		for (o, n) in map {
			let Some(o_p) = o.parent() else { continue };
			let Some(n_p) = n.url.parent() else { continue };
			if o_p == n_p {
				parents.entry_ref(&o_p).or_default().1.insert(o.urn().to_owned(), n);
			} else {
				parents.entry_ref(&o_p).or_default().0.insert(o.urn().to_owned());
				parents.entry_ref(&n_p).or_default().1.insert(n.urn().to_owned(), n);
			}
		}
		for (p, (o, n)) in parents {
			match (o.is_empty(), n.is_empty()) {
				(true, true) => unreachable!(),
				(true, false) => Self::Upserting(p, n).emit(),
				(false, true) => Self::Deleting(p, o).emit(),
				(false, false) => {
					Self::Deleting(p.clone(), o).emit();
					Self::Upserting(p, n).emit();
				}
			}
		}
	}

	pub fn mutate(ops: Vec<Self>) {
		let mut parents: HashMap<_, (HashMap<_, _>, HashSet<_>)> = Default::default();
		for op in ops {
			match op {
				Self::Upserting(p, map) => parents.entry(p).or_default().0.extend(map),
				Self::Deleting(p, urns) => parents.entry(p).or_default().1.extend(urns),
				_ => unreachable!(),
			}
		}
		for (p, (u, d)) in parents {