mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
f3179b7cf9
commit
c9e929fdc3
2 changed files with 9 additions and 10 deletions
|
|
@ -9,22 +9,22 @@ use yazi_shared::{natsort, replace_cow, replace_vec_cow};
|
||||||
use super::{Locked, Partition, Partitions};
|
use super::{Locked, Partition, Partitions};
|
||||||
|
|
||||||
impl Partitions {
|
impl Partitions {
|
||||||
pub fn monitor<F>(me: Locked, cb: F)
|
pub fn monitor<F>(me: &'static Locked, cb: F)
|
||||||
where
|
where
|
||||||
F: Fn() + Copy + Send + 'static,
|
F: Fn() + Copy + Send + 'static,
|
||||||
{
|
{
|
||||||
async fn wait_mounts(me: Locked, cb: impl Fn()) -> Result<()> {
|
async fn wait_mounts(me: &'static Locked, cb: impl Fn()) -> Result<()> {
|
||||||
let f = std::fs::File::open("/proc/mounts")?;
|
let f = std::fs::File::open("/proc/mounts")?;
|
||||||
let fd = AsyncFd::with_interest(f.as_fd(), Interest::READABLE)?;
|
let fd = AsyncFd::with_interest(f.as_fd(), Interest::READABLE)?;
|
||||||
loop {
|
loop {
|
||||||
let mut guard = fd.readable().await?;
|
let mut guard = fd.readable().await?;
|
||||||
guard.clear_ready();
|
guard.clear_ready();
|
||||||
Partitions::update(me.clone()).await;
|
Partitions::update(me).await;
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn wait_partitions(me: Locked, cb: impl Fn()) -> Result<()> {
|
async fn wait_partitions(me: &'static Locked, cb: impl Fn()) -> Result<()> {
|
||||||
loop {
|
loop {
|
||||||
let partitions = Partitions::partitions()?;
|
let partitions = Partitions::partitions()?;
|
||||||
if me.read().linux_cache == partitions {
|
if me.read().linux_cache == partitions {
|
||||||
|
|
@ -33,17 +33,16 @@ impl Partitions {
|
||||||
}
|
}
|
||||||
|
|
||||||
me.write().linux_cache = partitions;
|
me.write().linux_cache = partitions;
|
||||||
Partitions::update(me.clone()).await;
|
Partitions::update(me).await;
|
||||||
|
|
||||||
cb();
|
cb();
|
||||||
sleep(Duration::from_secs(3)).await;
|
sleep(Duration::from_secs(3)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let me_ = me.clone();
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
if let Err(e) = wait_mounts(me_.clone(), cb).await {
|
if let Err(e) = wait_mounts(me, cb).await {
|
||||||
error!("Error encountered while monitoring /proc/mounts: {e:?}");
|
error!("Error encountered while monitoring /proc/mounts: {e:?}");
|
||||||
}
|
}
|
||||||
sleep(Duration::from_secs(5)).await;
|
sleep(Duration::from_secs(5)).await;
|
||||||
|
|
@ -52,7 +51,7 @@ impl Partitions {
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
if let Err(e) = wait_partitions(me.clone(), cb).await {
|
if let Err(e) = wait_partitions(me, cb).await {
|
||||||
error!("Error encountered while monitoring /proc/partitions: {e:?}");
|
error!("Error encountered while monitoring /proc/partitions: {e:?}");
|
||||||
}
|
}
|
||||||
sleep(Duration::from_secs(5)).await;
|
sleep(Duration::from_secs(5)).await;
|
||||||
|
|
@ -75,7 +74,7 @@ impl Partitions {
|
||||||
Ok(set)
|
Ok(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(me: Locked) {
|
async fn update(me: &'static Locked) {
|
||||||
_ = tokio::task::spawn_blocking(move || {
|
_ = tokio::task::spawn_blocking(move || {
|
||||||
let mut guard = me.write();
|
let mut guard = me.write();
|
||||||
match Self::all(&guard) {
|
match Self::all(&guard) {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ macro_rules! ok_or_not_found {
|
||||||
($result:expr, $not_found:expr) => {
|
($result:expr, $not_found:expr) => {
|
||||||
match $result {
|
match $result {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(e) if e.kind() == io::ErrorKind::NotFound => $not_found,
|
Err(e) if e.kind() == std::io::ErrorKind::NotFound => $not_found,
|
||||||
Err(e) => Err(e)?,
|
Err(e) => Err(e)?,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue