mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
fix: unmangle the hexadecimal space strings ("\x20") in Linux partition labels (#2233)
This commit is contained in:
parent
245fb030df
commit
1f4d0eafb5
4 changed files with 31 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -3591,6 +3591,7 @@ dependencies = [
|
|||
"crossterm",
|
||||
"futures",
|
||||
"libc",
|
||||
"memchr",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"ratatui",
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use std::{borrow::Cow, collections::{HashMap, HashSet}, ffi::{OsStr, OsString}, os::{fd::AsFd, unix::{ffi::OsStrExt, 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 tokio::{io::{Interest, unix::AsyncFd}, time::sleep};
|
||||
use tracing::error;
|
||||
use yazi_shared::replace_cow;
|
||||
use yazi_shared::{replace_cow, replace_vec_cow};
|
||||
|
||||
use super::{Locked, Partition, Partitions};
|
||||
|
||||
|
|
@ -129,7 +129,14 @@ 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())?;
|
||||
map.insert((meta.dev(), meta.ino()), entry.file_name());
|
||||
let name = entry.file_name();
|
||||
map.insert(
|
||||
(meta.dev(), meta.ino()),
|
||||
match replace_vec_cow(name.as_bytes(), br"\x20", b" ") {
|
||||
Cow::Borrowed(_) => name,
|
||||
Cow::Owned(v) => OsString::from_vec(v),
|
||||
},
|
||||
);
|
||||
}
|
||||
Ok(map)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ yazi-macro = { path = "../yazi-macro", version = "0.4.3" }
|
|||
anyhow = { workspace = true }
|
||||
crossterm = { workspace = true }
|
||||
futures = { workspace = true }
|
||||
memchr = "2.7.4"
|
||||
parking_lot = { workspace = true }
|
||||
percent-encoding = "2.3.1"
|
||||
ratatui = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -64,6 +64,25 @@ fn replace_cow_impl<'s>(
|
|||
result + unsafe { src.get_unchecked(last..) }
|
||||
}
|
||||
|
||||
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]);
|
||||
out.extend_from_slice(to);
|
||||
last += from.len();
|
||||
|
||||
for idx in it {
|
||||
out.extend_from_slice(&v[last..idx]);
|
||||
out.extend_from_slice(to);
|
||||
last = idx + from.len();
|
||||
}
|
||||
|
||||
out.extend_from_slice(&v[last..]);
|
||||
Cow::Owned(out)
|
||||
}
|
||||
|
||||
pub fn replace_to_printable(s: &[String], tab_size: u8) -> String {
|
||||
let mut buf = Vec::new();
|
||||
buf.try_reserve_exact(s.iter().map(|s| s.len()).sum::<usize>() | 15).unwrap_or_else(|_| panic!());
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue