From e2c841cca461ddad4b26a3848672bd8a0a616d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Wed, 12 Feb 2025 17:10:07 +0800 Subject: [PATCH] fix: load mount points with the best effort even if the `/dev/disk/by-label` directory does not exist (#2326) --- yazi-fs/src/mounts/linux.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/yazi-fs/src/mounts/linux.rs b/yazi-fs/src/mounts/linux.rs index 68deda69..af983559 100644 --- a/yazi-fs/src/mounts/linux.rs +++ b/yazi-fs/src/mounts/linux.rs @@ -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 anyhow::Result; +use anyhow::{Context, Result}; use tokio::{io::{Interest, unix::AsyncFd}, time::sleep}; use tracing::error; use yazi_shared::{natsort, replace_cow, replace_vec_cow}; @@ -43,7 +43,7 @@ impl Partitions { tokio::spawn(async move { loop { 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; } @@ -52,7 +52,7 @@ impl Partitions { tokio::spawn(async move { loop { 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; } @@ -71,7 +71,7 @@ impl Partitions { } fn all(&self) -> Result> { - let mut mounts = Self::mounts()?; + let mut mounts = Self::mounts().context("Parsing /proc/mounts")?; { let set = &self.linux_cache; 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)); }; - let labels = Self::labels()?; + let labels = Self::labels(); for mount in &mut mounts { if !mount.src.as_bytes().starts_with(b"/dev/") { continue; @@ -126,10 +126,15 @@ impl Partitions { Ok(set) } - fn labels() -> Result> { + fn labels() -> HashMap<(u64, u64), OsString> { let mut map = HashMap::new(); - for entry in std::fs::read_dir("/dev/disk/by-label")?.flatten() { - let meta = std::fs::metadata(entry.path())?; + let Ok(it) = std::fs::read_dir("/dev/disk/by-label") else { + 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(); map.insert( (meta.dev(), meta.ino()), @@ -139,7 +144,7 @@ impl Partitions { }, ); } - Ok(map) + map } // Unmangle '\t', '\n', ' ', '#', and r'\'