From 1b2e10fb0a8a4664384c260cd6b1b5ea6055058b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20misaki=20masa?= Date: Wed, 22 Jul 2026 03:11:13 +0800 Subject: [PATCH] Fix a race condition in refresher --- yazi-watcher/src/refresher.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/yazi-watcher/src/refresher.rs b/yazi-watcher/src/refresher.rs index 4d7b4229..a73dad5a 100644 --- a/yazi-watcher/src/refresher.rs +++ b/yazi-watcher/src/refresher.rs @@ -1,6 +1,6 @@ use std::{io, ops::Deref, time::{Duration, Instant}}; -use hashbrown::HashMap; +use hashbrown::{HashMap, hash_map::RawEntryMut}; use indexmap::IndexSet; use tokio::sync::mpsc; use yazi_fs::{Entries, FilesOp, file::{File, FileCov}}; @@ -55,9 +55,17 @@ impl Refresher { } } Op::Refresh(files) => { - for file in files { - let entry = - entries.get_or_insert_with(file.0, |file| Entry { file, ..Default::default() }); + for file in files.into_iter().map(|file| file.0) { + let entry = match entries.raw_entry_mut().from_key(&file.url) { + RawEntryMut::Occupied(mut oe) => { + oe.get_mut().file = file; + oe.into_mut() + } + RawEntryMut::Vacant(ve) => { + ve.insert(file.url.to_owned(), Entry { file, ..Default::default() }).1 + } + }; + (entry.dirty, entry.report) = (true, true); self.spawn(entry); } @@ -98,6 +106,7 @@ impl Refresher { } entry.busy = None; + self.spawn(entry); // A new request may have arrived while this entry was busy. } } }