From 86665e788be7faa8ce93e0e4b6a0b49f5fa232d1 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Mon, 20 Oct 2025 13:36:03 +0800 Subject: [PATCH] .. --- yazi-fs/src/cwd.rs | 22 ++++++++++++++++------ yazi-fs/src/provider/local/local.rs | 20 +++++++++++--------- yazi-sftp/src/operator.rs | 3 +-- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/yazi-fs/src/cwd.rs b/yazi-fs/src/cwd.rs index 114800c7..ec4935d1 100644 --- a/yazi-fs/src/cwd.rs +++ b/yazi-fs/src/cwd.rs @@ -58,14 +58,24 @@ impl Cwd { return cache.into(); } - let count = cache.strip_prefix(Xdg::cache_dir()).expect("under cache dir").components().count(); - 'outer: for n in (0..count).rev() { + let latter = cache.strip_prefix(Xdg::cache_dir()).expect("under cache dir"); + let mut it = latter.components().peekable(); + while it.peek() == Some(&C::CurDir) { + it.next().unwrap(); + } + + let mut count = 0; + for c in it { + match c { + C::Prefix(_) | C::RootDir | C::ParentDir => return cache.into(), + C::CurDir | C::Normal(_) => count += 1, + } + } + + for n in (0..count).rev() { let mut it = cache.components(); for _ in 0..n { - match it.next_back().unwrap() { - C::Prefix(_) | C::RootDir | C::ParentDir => break 'outer, - C::CurDir | C::Normal(_) => {} - } + it.next_back().unwrap(); } match std::fs::remove_file(it.as_path()) { Ok(_) => break, diff --git a/yazi-fs/src/provider/local/local.rs b/yazi-fs/src/provider/local/local.rs index f2834bfc..4815ee30 100644 --- a/yazi-fs/src/provider/local/local.rs +++ b/yazi-fs/src/provider/local/local.rs @@ -238,17 +238,19 @@ impl Local { use std::os::unix::fs::OpenOptionsExt; tokio::task::spawn_blocking(move || { - let mut reader = std::fs::File::open(from)?; - let mut writer = std::fs::OpenOptions::new() - .mode(cha.mode.bits() as _) - .write(true) - .create(true) - .truncate(true) - .open(to)?; + let mut opts = std::fs::OpenOptions::new(); + if let Some(mode) = attrs.mode { + opts.mode(mode.bits() as _); + } + let mut reader = std::fs::File::open(from)?; + let mut writer = opts.write(true).create(true).truncate(true).open(to)?; let written = std::io::copy(&mut reader, &mut writer)?; - writer.set_permissions(cha.into()).ok(); - writer.set_times(cha.into()).ok(); + + if let Some(mode) = attrs.mode { + writer.set_permissions(mode.into()).ok(); + } + writer.set_times(attrs.into()).ok(); Ok(written) }) diff --git a/yazi-sftp/src/operator.rs b/yazi-sftp/src/operator.rs index 181eaf58..1620d4f4 100644 --- a/yazi-sftp/src/operator.rs +++ b/yazi-sftp/src/operator.rs @@ -142,8 +142,7 @@ impl Operator { F: ToByteStr<'a>, T: ToByteStr<'a>, { - let req = requests::Rename::new(from, to)?; - let status: responses::Status = self.send(req).await?; + let status: responses::Status = self.send(requests::Rename::new(from, to)?).await?; status.into() }