mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: load mount points with the best effort even if the /dev/disk/by-label directory does not exist (#2326)
This commit is contained in:
parent
a4dde6a848
commit
e2c841cca4
1 changed files with 14 additions and 9 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{borrow::Cow, collections::{HashMap, HashSet}, ffi::{OsStr, OsString}, os::{fd::AsFd, unix::{ffi::{OsStrExt, OsStringExt}, fs::MetadataExt}}, time::Duration};
|
use std::{borrow::Cow, collections::{HashMap, HashSet}, ffi::{OsStr, OsString}, os::{fd::AsFd, unix::{ffi::{OsStrExt, OsStringExt}, fs::MetadataExt}}, time::Duration};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::{Context, Result};
|
||||||
use tokio::{io::{Interest, unix::AsyncFd}, time::sleep};
|
use tokio::{io::{Interest, unix::AsyncFd}, time::sleep};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
use yazi_shared::{natsort, replace_cow, replace_vec_cow};
|
use yazi_shared::{natsort, replace_cow, replace_vec_cow};
|
||||||
|
|
@ -43,7 +43,7 @@ impl Partitions {
|
||||||
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_.clone(), 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 +52,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.clone(), 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;
|
||||||
}
|
}
|
||||||
|
|
@ -71,7 +71,7 @@ impl Partitions {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all(&self) -> Result<Vec<Partition>> {
|
fn all(&self) -> Result<Vec<Partition>> {
|
||||||
let mut mounts = Self::mounts()?;
|
let mut mounts = Self::mounts().context("Parsing /proc/mounts")?;
|
||||||
{
|
{
|
||||||
let set = &self.linux_cache;
|
let set = &self.linux_cache;
|
||||||
let mut set: HashSet<&OsStr> = set.iter().map(AsRef::as_ref).collect();
|
let mut set: HashSet<&OsStr> = set.iter().map(AsRef::as_ref).collect();
|
||||||
|
|
@ -80,7 +80,7 @@ impl Partitions {
|
||||||
mounts.sort_unstable_by(|a, b| natsort(a.src.as_bytes(), b.src.as_bytes(), false));
|
mounts.sort_unstable_by(|a, b| natsort(a.src.as_bytes(), b.src.as_bytes(), false));
|
||||||
};
|
};
|
||||||
|
|
||||||
let labels = Self::labels()?;
|
let labels = Self::labels();
|
||||||
for mount in &mut mounts {
|
for mount in &mut mounts {
|
||||||
if !mount.src.as_bytes().starts_with(b"/dev/") {
|
if !mount.src.as_bytes().starts_with(b"/dev/") {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -126,10 +126,15 @@ impl Partitions {
|
||||||
Ok(set)
|
Ok(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn labels() -> Result<HashMap<(u64, u64), OsString>> {
|
fn labels() -> HashMap<(u64, u64), OsString> {
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
for entry in std::fs::read_dir("/dev/disk/by-label")?.flatten() {
|
let Ok(it) = std::fs::read_dir("/dev/disk/by-label") else {
|
||||||
let meta = std::fs::metadata(entry.path())?;
|
error!("Cannot read /dev/disk/by-label");
|
||||||
|
return map;
|
||||||
|
};
|
||||||
|
|
||||||
|
for entry in it.flatten() {
|
||||||
|
let Ok(meta) = std::fs::metadata(entry.path()) else { continue };
|
||||||
let name = entry.file_name();
|
let name = entry.file_name();
|
||||||
map.insert(
|
map.insert(
|
||||||
(meta.dev(), meta.ino()),
|
(meta.dev(), meta.ino()),
|
||||||
|
|
@ -139,7 +144,7 @@ impl Partitions {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Ok(map)
|
map
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmangle '\t', '\n', ' ', '#', and r'\'
|
// Unmangle '\t', '\n', ' ', '#', and r'\'
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue