mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41: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",
|
"crossterm",
|
||||||
"futures",
|
"futures",
|
||||||
"libc",
|
"libc",
|
||||||
|
"memchr",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"ratatui",
|
"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 anyhow::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::replace_cow;
|
use yazi_shared::{replace_cow, replace_vec_cow};
|
||||||
|
|
||||||
use super::{Locked, Partition, Partitions};
|
use super::{Locked, Partition, Partitions};
|
||||||
|
|
||||||
|
|
@ -129,7 +129,14 @@ impl Partitions {
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
for entry in std::fs::read_dir("/dev/disk/by-label")?.flatten() {
|
for entry in std::fs::read_dir("/dev/disk/by-label")?.flatten() {
|
||||||
let meta = std::fs::metadata(entry.path())?;
|
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)
|
Ok(map)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ yazi-macro = { path = "../yazi-macro", version = "0.4.3" }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
crossterm = { workspace = true }
|
crossterm = { workspace = true }
|
||||||
futures = { workspace = true }
|
futures = { workspace = true }
|
||||||
|
memchr = "2.7.4"
|
||||||
parking_lot = { workspace = true }
|
parking_lot = { workspace = true }
|
||||||
percent-encoding = "2.3.1"
|
percent-encoding = "2.3.1"
|
||||||
ratatui = { workspace = true }
|
ratatui = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,25 @@ fn replace_cow_impl<'s>(
|
||||||
result + unsafe { src.get_unchecked(last..) }
|
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 {
|
pub fn replace_to_printable(s: &[String], tab_size: u8) -> String {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
buf.try_reserve_exact(s.iter().map(|s| s.len()).sum::<usize>() | 15).unwrap_or_else(|_| panic!());
|
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