Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: load mount points with the best effort even if the /dev/disk/by-label directory does not exist #2326

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions yazi-fs/src/mounts/linux.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -71,7 +71,7 @@ impl Partitions {
}

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 mut set: HashSet<&OsStr> = set.iter().map(AsRef::as_ref).collect();
Expand All @@ -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;
Expand Down Expand Up @@ -126,10 +126,15 @@ impl Partitions {
Ok(set)
}

fn labels() -> Result<HashMap<(u64, u64), OsString>> {
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()),
Expand All @@ -139,7 +144,7 @@ impl Partitions {
},
);
}
Ok(map)
map
}

// Unmangle '\t', '\n', ' ', '#', and r'\'
Expand Down
Loading