Simplify the code

This commit is contained in:
sxyazi 2025-05-19 23:29:26 +08:00
parent 0f56ba88f3
commit 49050ba031
No known key found for this signature in database
2 changed files with 10 additions and 9 deletions

4
Cargo.lock generated
View file

@ -346,9 +346,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.2.22"
version = "1.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32db95edf998450acc7881c932f94cd9b05c87b4b2599e8bab064753da4acfd1"
checksum = "5f4ac86a9e5bc1e2b3449ab9d7d3a6a405e3d1bb28d7b9be8614f55846ae3766"
dependencies = [
"jobserver",
"libc",

View file

@ -1,4 +1,4 @@
use std::{borrow::Cow, mem, path::{MAIN_SEPARATOR_STR, PathBuf}};
use std::{borrow::Cow, ffi::OsString, mem, path::{MAIN_SEPARATOR_STR, Path, PathBuf}};
use tokio::fs;
use yazi_fs::{CWD, expand_path};
@ -44,18 +44,19 @@ impl Cmp {
tokio::spawn(async move {
let mut dir = fs::read_dir(&parent).await?;
let mut cache = vec![];
// "/" is both a directory separator and the root directory per se
// As there's no parent directory for the FS root, it is a special case
if parent == Path::new("/") {
cache.push(CmpItem { name: OsString::new(), is_dir: true });
}
while let Ok(Some(ent)) = dir.next_entry().await {
if let Ok(ft) = ent.file_type().await {
cache.push(CmpItem { name: ent.file_name(), is_dir: ft.is_dir() });
}
}
// "/" is both a directory separator and the root directory per se
// As there's no parent directory for the FS root, it is a special case
if parent.as_path() == std::path::Path::new("/") {
cache.push(CmpItem { name: "".into(), is_dir: true });
}
if !cache.is_empty() {
cache.sort_unstable_by(|a, b| {
natsort(a.name.as_encoded_bytes(), b.name.as_encoded_bytes(), false)