From f49a03c424a085ecb2ce687efef820d900e40487 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Mon, 28 Jul 2025 17:16:20 +0800 Subject: [PATCH] .. --- Cargo.lock | 33 ++++----- Cargo.toml | 2 +- yazi-fs/src/services/services.rs | 114 +++++++++++++++++++++++++----- yazi-parser/src/mgr/cd.rs | 12 +++- yazi-parser/src/mgr/reveal.rs | 11 ++- yazi-parser/src/mgr/tab_create.rs | 10 ++- 6 files changed, 132 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53ecdc9c..9d6d1b63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1357,9 +1357,9 @@ checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" [[package]] name = "litrs" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" +checksum = "f5e54036fe321fd421e10d732f155734c4e4afd610dd556d9a82833ab3ee0bed" [[package]] name = "lock_api" @@ -2155,9 +2155,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.15" +version = "0.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8af0dde094006011e6a740d4879319439489813bd0bcdc7d821beaeeff48ec" +checksum = "7251471db004e509f4e75a62cca9435365b5ec7bcdff530d612ac7c87c44a792" dependencies = [ "bitflags 2.9.1", ] @@ -2225,9 +2225,9 @@ checksum = "0c6a884d2998352bb4daf0183589aec883f16a6da1f4dde84d8e2e9a5409a1ce" [[package]] name = "rustc-demangle" -version = "0.1.25" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" +checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace" [[package]] name = "rustc-hash" @@ -2470,12 +2470,12 @@ checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" [[package]] name = "socket2" -version = "0.5.10" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2684,9 +2684,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.46.1" +version = "1.47.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17" +checksum = "43864ed400b6043a4757a25c7a64a8efde741aed79a056a2fb348a406701bb35" dependencies = [ "backtrace", "bytes", @@ -2699,7 +2699,7 @@ dependencies = [ "slab", "socket2", "tokio-macros", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -3295,15 +3295,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-sys" version = "0.59.0" diff --git a/Cargo.toml b/Cargo.toml index 239f1556..958f0899 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ scopeguard = "1.2.0" serde = { version = "1.0.219", features = [ "derive" ] } serde_json = "1.0.141" syntect = { version = "5.2.0", default-features = false, features = [ "parsing", "plist-load", "regex-onig" ] } -tokio = { version = "1.46.1", features = [ "full" ] } +tokio = { version = "1.47.0", features = [ "full" ] } tokio-stream = "0.1.17" tokio-util = "0.7.15" toml = { version = "0.9.2" } diff --git a/yazi-fs/src/services/services.rs b/yazi-fs/src/services/services.rs index c797501b..2b8cba8d 100644 --- a/yazi-fs/src/services/services.rs +++ b/yazi-fs/src/services/services.rs @@ -6,94 +6,170 @@ use crate::services::Local; #[inline] pub async fn canonicalize(url: impl AsRef) -> io::Result { - Local::canonicalize(url.as_ref()).await.map(Into::into) + if let Some(path) = url.as_ref().as_path() { + Local::canonicalize(path).await.map(Into::into) + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn create(url: impl AsRef) -> io::Result { - Local::create(url.as_ref()).await + if let Some(path) = url.as_ref().as_path() { + Local::create(path).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn create_dir(url: impl AsRef) -> io::Result<()> { - Local::create_dir(url.as_ref()).await + if let Some(path) = url.as_ref().as_path() { + Local::create_dir(path).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn create_dir_all(url: impl AsRef) -> io::Result<()> { - Local::create_dir_all(url.as_ref()).await + if let Some(path) = url.as_ref().as_path() { + Local::create_dir_all(path).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn hard_link(original: impl AsRef, link: impl AsRef) -> io::Result<()> { - Local::hard_link(original.as_ref(), link.as_ref()).await + if let (Some(original), Some(link)) = (original.as_ref().as_path(), link.as_ref().as_path()) { + Local::hard_link(original, link).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn metadata(url: impl AsRef) -> io::Result { - Local::metadata(url.as_ref()).await + if let Some(path) = url.as_ref().as_path() { + Local::metadata(path).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn open(url: impl AsRef) -> io::Result { - Local::open(url.as_ref()).await + if let Some(path) = url.as_ref().as_path() { + Local::open(path).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn read_dir(url: impl AsRef) -> io::Result { - Local::read_dir(url.as_ref()).await + if let Some(path) = url.as_ref().as_path() { + Local::read_dir(path).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub fn read_dir_sync(url: impl AsRef) -> io::Result { - Local::read_dir_sync(url.as_ref()) + if let Some(path) = url.as_ref().as_path() { + Local::read_dir_sync(path) + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn read_link(url: impl AsRef) -> io::Result { - Local::read_link(url.as_ref()).await.map(Into::into) + if let Some(path) = url.as_ref().as_path() { + Local::read_link(path).await.map(Into::into) + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn remove_dir(url: impl AsRef) -> io::Result<()> { - Local::remove_dir(url.as_ref()).await + if let Some(path) = url.as_ref().as_path() { + Local::remove_dir(path).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn remove_dir_all(url: impl AsRef) -> io::Result<()> { - Local::remove_dir_all(url.as_ref()).await + if let Some(path) = url.as_ref().as_path() { + Local::remove_dir_all(path).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn remove_file(url: impl AsRef) -> io::Result<()> { - Local::remove_file(url.as_ref()).await + if let Some(path) = url.as_ref().as_path() { + Local::remove_file(path).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn rename(from: impl AsRef, to: impl AsRef) -> io::Result<()> { - Local::rename(from.as_ref(), to.as_ref()).await + if let (Some(from), Some(to)) = (from.as_ref().as_path(), to.as_ref().as_path()) { + Local::rename(from, to).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn symlink_dir(original: impl AsRef, link: impl AsRef) -> io::Result<()> { - Local::symlink_dir(original.as_ref(), link.as_ref()).await + if let (Some(original), Some(link)) = (original.as_ref().as_path(), link.as_ref().as_path()) { + Local::symlink_dir(original, link).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn symlink_file(original: impl AsRef, link: impl AsRef) -> io::Result<()> { - Local::symlink_file(original.as_ref(), link.as_ref()).await + if let (Some(original), Some(link)) = (original.as_ref().as_path(), link.as_ref().as_path()) { + Local::symlink_file(original, link).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn symlink_metadata(url: impl AsRef) -> io::Result { - Local::symlink_metadata(url.as_ref()).await + if let Some(path) = url.as_ref().as_path() { + Local::symlink_metadata(path).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } pub fn symlink_metadata_sync(url: impl AsRef) -> io::Result { - Local::symlink_metadata_sync(url.as_ref()) + if let Some(path) = url.as_ref().as_path() { + Local::symlink_metadata_sync(path) + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } #[inline] pub async fn write(url: impl AsRef, contents: impl AsRef<[u8]>) -> io::Result<()> { - Local::write(url.as_ref(), contents).await + if let Some(path) = url.as_ref().as_path() { + Local::write(path, contents).await + } else { + Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported filesystem")) + } } diff --git a/yazi-parser/src/mgr/cd.rs b/yazi-parser/src/mgr/cd.rs index d1ced338..b74a7907 100644 --- a/yazi-parser/src/mgr/cd.rs +++ b/yazi-parser/src/mgr/cd.rs @@ -1,5 +1,7 @@ +use std::borrow::Cow; + use mlua::{ExternalError, IntoLua, Lua, Value}; -use yazi_fs::expand_path; +use yazi_fs::expand_url; use yazi_shared::{event::CmdCow, url::Url}; #[derive(Debug)] @@ -12,9 +14,13 @@ pub struct CdOpt { impl From for CdOpt { fn from(mut c: CmdCow) -> Self { let mut target = c.take_first_url().unwrap_or_default(); - if target.is_regular() && !c.bool("raw") { - target = Url::from(expand_path(target)); + + if !c.bool("raw") + && let Cow::Owned(u) = expand_url(&target) + { + target = u; } + Self { target, interactive: c.bool("interactive"), source: CdSource::Cd } } } diff --git a/yazi-parser/src/mgr/reveal.rs b/yazi-parser/src/mgr/reveal.rs index c5938ff2..70805bd8 100644 --- a/yazi-parser/src/mgr/reveal.rs +++ b/yazi-parser/src/mgr/reveal.rs @@ -1,5 +1,7 @@ +use std::borrow::Cow; + use mlua::{ExternalError, IntoLua, Lua, Value}; -use yazi_fs::expand_path; +use yazi_fs::expand_url; use yazi_shared::{event::CmdCow, url::Url}; use crate::mgr::CdSource; @@ -14,8 +16,11 @@ pub struct RevealOpt { impl From for RevealOpt { fn from(mut c: CmdCow) -> Self { let mut target = c.take_first_url().unwrap_or_default(); - if target.is_regular() && !c.bool("raw") { - target = Url::from(expand_path(target)); + + if !c.bool("raw") + && let Cow::Owned(u) = expand_url(&target) + { + target = u; } Self { target, source: CdSource::Reveal, no_dummy: c.bool("no-dummy") } diff --git a/yazi-parser/src/mgr/tab_create.rs b/yazi-parser/src/mgr/tab_create.rs index 4e1da1f4..b8862fa0 100644 --- a/yazi-parser/src/mgr/tab_create.rs +++ b/yazi-parser/src/mgr/tab_create.rs @@ -1,6 +1,8 @@ +use std::borrow::Cow; + use mlua::{ExternalError, IntoLua, Lua, Value}; use yazi_boot::BOOT; -use yazi_fs::expand_path; +use yazi_fs::expand_url; use yazi_shared::{event::CmdCow, url::Url}; #[derive(Debug)] @@ -16,8 +18,10 @@ impl From for TabCreateOpt { let Some(mut wd) = c.take_first_url() else { return Self { wd: Some(Url::from(&BOOT.cwds[0])) }; }; - if wd.is_regular() && !c.bool("raw") { - wd = Url::from(expand_path(wd)); + if !c.bool("raw") + && let Cow::Owned(u) = expand_url(&wd) + { + wd = u; } Self { wd: Some(wd) } }