mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Some checks failed
Cachix / Publish Flake (push) Has been cancelled
Check / clippy (push) Has been cancelled
Check / rustfmt (push) Has been cancelled
Check / stylua (push) Has been cancelled
Draft / build-unix (gcc-aarch64-linux-gnu, ubuntu-latest, aarch64-unknown-linux-gnu) (push) Has been cancelled
Draft / build-unix (gcc-i686-linux-gnu, ubuntu-latest, i686-unknown-linux-gnu) (push) Has been cancelled
Draft / build-unix (gcc-riscv64-linux-gnu, ubuntu-latest, riscv64gc-unknown-linux-gnu) (push) Has been cancelled
Draft / build-unix (gcc-sparc64-linux-gnu, ubuntu-latest, sparc64-unknown-linux-gnu) (push) Has been cancelled
Draft / build-unix (macos-latest, aarch64-apple-darwin) (push) Has been cancelled
Draft / build-unix (macos-latest, x86_64-apple-darwin) (push) Has been cancelled
Draft / build-unix (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Has been cancelled
Draft / build-windows (windows-latest, aarch64-pc-windows-msvc) (push) Has been cancelled
Draft / build-windows (windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
Draft / build-musl (aarch64-unknown-linux-musl) (push) Has been cancelled
Draft / build-musl (x86_64-unknown-linux-musl) (push) Has been cancelled
Draft / build-snap (amd64, ubuntu-latest) (push) Has been cancelled
Draft / build-snap (arm64, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (macos-latest) (push) Has been cancelled
Test / test (ubuntu-latest) (push) Has been cancelled
Test / test (windows-latest) (push) Has been cancelled
Draft / snap (push) Has been cancelled
Draft / draft (push) Has been cancelled
Draft / nightly (push) Has been cancelled
62 lines
1.7 KiB
Rust
62 lines
1.7 KiB
Rust
use tokio::sync::mpsc;
|
|
use yazi_shared::{auth::AuthKind, url::{AsUrl, Url, UrlBuf, UrlCow, UrlLike}};
|
|
|
|
use crate::{WATCHED, local::LINKED, r#virtual::VirtualReport};
|
|
|
|
#[derive(Clone)]
|
|
pub(crate) struct Reporter {
|
|
pub(super) local_tx: mpsc::UnboundedSender<UrlBuf>,
|
|
pub(super) virtual_tx: mpsc::UnboundedSender<VirtualReport>,
|
|
}
|
|
|
|
impl Reporter {
|
|
pub(crate) fn report<'a, I>(&self, urls: I)
|
|
where
|
|
I: IntoIterator,
|
|
I::Item: Into<UrlCow<'a>>,
|
|
{
|
|
for url in urls.into_iter().map(Into::into) {
|
|
match url.as_url().kind() {
|
|
AuthKind::Regular | AuthKind::Search => self.report_local(url),
|
|
AuthKind::Mount | AuthKind::Hub | AuthKind::Scope | AuthKind::Sftp => {
|
|
self.report_virtual(url)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fn report_local(&self, url: UrlCow) {
|
|
let Some((parent, urn)) = url.pair() else { return };
|
|
|
|
// FIXME: LINKED should return Url instead of Path
|
|
let linked = LINKED.read();
|
|
let linked = linked.from_dir(parent).map(Url::regular);
|
|
|
|
let watched = WATCHED.read();
|
|
for parent in [parent].into_iter().chain(linked) {
|
|
if watched.contains_url(parent) {
|
|
self.local_tx.send(url.to_owned()).ok();
|
|
self.local_tx.send(parent.to_owned()).ok();
|
|
}
|
|
|
|
if urn.ext().is_some_and(|e| e == "%tmp") {
|
|
continue;
|
|
}
|
|
|
|
// Virtual caches
|
|
let Some(dir) = watched.find_by_cache(parent.loc()) else { continue };
|
|
let Some(key) = url.name() else { continue };
|
|
self.virtual_tx.send(VirtualReport::Cache(dir, key.to_owned())).ok();
|
|
}
|
|
}
|
|
|
|
fn report_virtual(&self, url: UrlCow) {
|
|
let Some(parent) = url.parent() else { return };
|
|
if !WATCHED.read().contains_url(parent) {
|
|
return;
|
|
}
|
|
|
|
self.virtual_tx.send(VirtualReport::Url(parent.to_owned())).ok();
|
|
self.virtual_tx.send(VirtualReport::Url(url.into_owned())).ok();
|
|
}
|
|
}
|