diff --git a/yazi-fs/src/mounts/linux.rs b/yazi-fs/src/mounts/linux.rs index de42c49c..980a9e39 100644 --- a/yazi-fs/src/mounts/linux.rs +++ b/yazi-fs/src/mounts/linux.rs @@ -3,7 +3,7 @@ use std::{borrow::Cow, collections::{HashMap, HashSet}, ffi::{OsStr, OsString}, use anyhow::Result; use tokio::{io::{Interest, unix::AsyncFd}, time::sleep}; use tracing::error; -use yazi_shared::{replace_cow, replace_vec}; +use yazi_shared::{replace_cow, replace_vec_cow}; use super::{Locked, Partition, Partitions}; @@ -129,9 +129,13 @@ impl Partitions { 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 name = entry.file_name(); map.insert( (meta.dev(), meta.ino()), - OsString::from_vec(replace_vec(entry.file_name().into_vec(), br"\x20", b" ")), + match replace_vec_cow(name.as_bytes(), br"\x20", b" ") { + Cow::Borrowed(_) => name, + Cow::Owned(v) => OsString::from_vec(v), + }, ); } Ok(map) diff --git a/yazi-shared/src/chars.rs b/yazi-shared/src/chars.rs index 858e6c04..c76ce38f 100644 --- a/yazi-shared/src/chars.rs +++ b/yazi-shared/src/chars.rs @@ -64,9 +64,9 @@ fn replace_cow_impl<'s>( result + unsafe { src.get_unchecked(last..) } } -pub fn replace_vec(v: Vec, from: &[u8], to: &[u8]) -> Vec { - let mut it = memchr::memmem::find_iter(&v, from); - let Some(mut last) = it.next() else { return v }; +pub fn replace_vec_cow<'a>(v: &'a [u8], from: &[u8], to: &[u8]) -> Cow<'a, [u8]> { + let mut it = memchr::memmem::find_iter(v, from); + let Some(mut last) = it.next() else { return Cow::Borrowed(v) }; let mut out = Vec::with_capacity(v.len()); out.extend_from_slice(&v[..last]); @@ -80,7 +80,7 @@ pub fn replace_vec(v: Vec, from: &[u8], to: &[u8]) -> Vec { } out.extend_from_slice(&v[last..]); - out + Cow::Owned(out) } pub fn replace_to_printable(s: &[String], tab_size: u8) -> String {