From 49050ba031d3acba6180f4ad141041d312fac55a Mon Sep 17 00:00:00 2001 From: sxyazi Date: Mon, 19 May 2025 23:29:26 +0800 Subject: [PATCH] Simplify the code --- Cargo.lock | 4 ++-- yazi-core/src/cmp/commands/trigger.rs | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb74512d..54133854 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/yazi-core/src/cmp/commands/trigger.rs b/yazi-core/src/cmp/commands/trigger.rs index ca282dd6..713d6735 100644 --- a/yazi-core/src/cmp/commands/trigger.rs +++ b/yazi-core/src/cmp/commands/trigger.rs @@ -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)