fix: add --follow option to paste command (#436)

This commit is contained in:
Mag Mell 2024-01-01 22:05:56 +08:00 committed by GitHub
parent 5fb0fceacb
commit 6b0495f2c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 7 deletions

View file

@ -3,11 +3,14 @@ use yazi_shared::event::Exec;
use crate::{manager::Manager, tasks::Tasks}; use crate::{manager::Manager, tasks::Tasks};
pub struct Opt { pub struct Opt {
force: bool, force: bool,
follow: bool,
} }
impl From<&Exec> for Opt { impl From<&Exec> for Opt {
fn from(e: &Exec) -> Self { Self { force: e.named.contains_key("force") } } fn from(e: &Exec) -> Self {
Self { force: e.named.contains_key("force"), follow: e.named.contains_key("follow") }
}
} }
impl Manager { impl Manager {
@ -16,6 +19,10 @@ impl Manager {
let (cut, ref src) = self.yanked; let (cut, ref src) = self.yanked;
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
if cut { tasks.file_cut(src, dest, opt.force) } else { tasks.file_copy(src, dest, opt.force) } if cut {
tasks.file_cut(src, dest, opt.force)
} else {
tasks.file_copy(src, dest, opt.force, opt.follow)
}
} }
} }

View file

@ -89,13 +89,13 @@ impl Tasks {
false false
} }
pub fn file_copy(&self, src: &HashSet<Url>, dest: &Url, force: bool) -> bool { pub fn file_copy(&self, src: &HashSet<Url>, dest: &Url, force: bool, follow: bool) -> bool {
for u in src { for u in src {
let to = dest.join(u.file_name().unwrap()); let to = dest.join(u.file_name().unwrap());
if force && u == &to { if force && u == &to {
debug!("file_copy: same file, skipping {:?}", to); debug!("file_copy: same file, skipping {:?}", to);
} else { } else {
self.scheduler.file_copy(u.clone(), to, force); self.scheduler.file_copy(u.clone(), to, force, follow);
} }
} }
false false

View file

@ -207,7 +207,7 @@ impl Scheduler {
); );
} }
pub fn file_copy(&self, from: Url, mut to: Url, force: bool) { pub fn file_copy(&self, from: Url, mut to: Url, force: bool, follow: bool) {
let name = format!("Copy {:?} to {:?}", from, to); let name = format!("Copy {:?} to {:?}", from, to);
let id = self.running.write().add(TaskKind::User, name); let id = self.running.write().add(TaskKind::User, name);
@ -217,7 +217,7 @@ impl Scheduler {
if !force { if !force {
to = unique_path(to).await; to = unique_path(to).await;
} }
file.paste(FileOpPaste { id, from, to, cut: false, follow: true, retry: 0 }).await.ok(); file.paste(FileOpPaste { id, from, to, cut: false, follow, retry: 0 }).await.ok();
} }
.boxed(), .boxed(),
LOW, LOW,