mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
5d10a60f25
commit
f4483c989c
2 changed files with 10 additions and 6 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -64,9 +64,9 @@ fn replace_cow_impl<'s>(
|
|||
result + unsafe { src.get_unchecked(last..) }
|
||||
}
|
||||
|
||||
pub fn replace_vec(v: Vec<u8>, from: &[u8], to: &[u8]) -> Vec<u8> {
|
||||
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<u8>, from: &[u8], to: &[u8]) -> Vec<u8> {
|
|||
}
|
||||
|
||||
out.extend_from_slice(&v[last..]);
|
||||
out
|
||||
Cow::Owned(out)
|
||||
}
|
||||
|
||||
pub fn replace_to_printable(s: &[String], tab_size: u8) -> String {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue