fix: fix incorrect warning when plugin doesn't exist

Fixes #2415.
This commit is contained in:
hankertrix 2025-02-28 22:09:21 +08:00
parent 84d71bfa39
commit b04e8382d0

View file

@ -20,7 +20,9 @@ impl Deref for Loader {
type Target = RwLock<HashMap<String, Chunk>>; type Target = RwLock<HashMap<String, Chunk>>;
#[inline] #[inline]
fn deref(&self) -> &Self::Target { &self.cache } fn deref(&self) -> &Self::Target {
&self.cache
}
} }
impl Default for Loader { impl Default for Loader {
@ -61,6 +63,13 @@ impl Loader {
Ok(b) => b, Ok(b) => b,
Err(e) if e.kind() == std::io::ErrorKind::NotFound => { Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
static WARNED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); static WARNED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
let p = BOOT.plugin_dir.join(format!("{name}.yazi/init.lua"));
match fs::read(&p).await {
Err(e) => Err(e).with_context(|| format!("Failed to load plugin from {p:?}"))?,
Ok(b) => {
if !WARNED.swap(true, std::sync::atomic::Ordering::Relaxed) { if !WARNED.swap(true, std::sync::atomic::Ordering::Relaxed) {
yazi_proxy::AppProxy::notify(yazi_proxy::options::NotifyOpt { yazi_proxy::AppProxy::notify(yazi_proxy::options::NotifyOpt {
title: "Deprecated entry file".to_owned(), title: "Deprecated entry file".to_owned(),
@ -73,9 +82,9 @@ Please run `ya pack -m` to automatically migrate all plugins, or manually rename
timeout: std::time::Duration::from_secs(25), timeout: std::time::Duration::from_secs(25),
}); });
} }
b
let p = BOOT.plugin_dir.join(format!("{name}.yazi/init.lua")); }
fs::read(&p).await.with_context(|| format!("Failed to load plugin from {p:?}"))? }
} }
Err(e) => Err(e).with_context(|| format!("Failed to load plugin from {p:?}"))?, Err(e) => Err(e).with_context(|| format!("Failed to load plugin from {p:?}"))?,
}; };