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};
|
||||
|
||||
impl Partitions {
|
||||
pub fn monitor<F>(me: Locked, cb: F)
|
||||
pub fn monitor<F>(me: &'static Locked, cb: F)
|
||||
where
|
||||
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 fd = AsyncFd::with_interest(f.as_fd(), Interest::READABLE)?;
|
||||
loop {
|
||||
let mut guard = fd.readable().await?;
|
||||
guard.clear_ready();
|
||||
Partitions::update(me.clone()).await;
|
||||
Partitions::update(me).await;
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
||||
async fn wait_partitions(me: Locked, cb: impl Fn()) -> Result<()> {
|
||||
async fn wait_partitions(me: &'static Locked, cb: impl Fn()) -> Result<()> {
|
||||
loop {
|
||||
let partitions = Partitions::partitions()?;
|
||||
if me.read().linux_cache == partitions {
|
||||
|
|
@ -33,17 +33,16 @@ impl Partitions {
|
|||
}
|
||||
|
||||
me.write().linux_cache = partitions;
|
||||
Partitions::update(me.clone()).await;
|
||||
Partitions::update(me).await;
|
||||
|
||||
cb();
|
||||
sleep(Duration::from_secs(3)).await;
|
||||
}
|
||||
}
|
||||
|
||||
let me_ = me.clone();
|
||||
tokio::spawn(async move {
|
||||
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:?}");
|
||||
}
|
||||
sleep(Duration::from_secs(5)).await;
|
||||
|
|
@ -52,7 +51,7 @@ impl Partitions {
|
|||
|
||||
tokio::spawn(async move {
|
||||
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:?}");
|
||||
}
|
||||
sleep(Duration::from_secs(5)).await;
|
||||
|
|
@ -75,7 +74,7 @@ impl Partitions {
|
|||
Ok(set)
|
||||
}
|
||||
|
||||
async fn update(me: Locked) {
|
||||
async fn update(me: &'static Locked) {
|
||||
_ = tokio::task::spawn_blocking(move || {
|
||||
let mut guard = me.write();
|
||||
match Self::all(&guard) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ macro_rules! ok_or_not_found {
|
|||
($result:expr, $not_found:expr) => {
|
||||
match $result {
|
||||
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)?,
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue