mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: prevent pasting a directory into itself (#925)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
669373a030
commit
a0b4ee6e6e
1 changed files with 17 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
use std::{borrow::Cow, ffi::OsString, sync::Arc, time::Duration};
|
use std::{borrow::Cow, ffi::OsString, sync::Arc, time::Duration};
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
use futures::{future::BoxFuture, FutureExt};
|
use futures::{future::BoxFuture, FutureExt};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use tokio::{fs, select, sync::{mpsc::{self, UnboundedReceiver}, oneshot}, task::JoinHandle};
|
use tokio::{fs, select, sync::{mpsc::{self, UnboundedReceiver}, oneshot}, task::JoinHandle};
|
||||||
|
|
@ -71,6 +72,11 @@ impl Scheduler {
|
||||||
let mut ongoing = self.ongoing.lock();
|
let mut ongoing = self.ongoing.lock();
|
||||||
let id = ongoing.add(TaskKind::User, format!("Cut {:?} to {:?}", from, to));
|
let id = ongoing.add(TaskKind::User, format!("Cut {:?} to {:?}", from, to));
|
||||||
|
|
||||||
|
if to.starts_with(&from) && to != from {
|
||||||
|
self.new_and_fail(id, "Cannot cut directory into itself").ok();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ongoing.hooks.insert(id, {
|
ongoing.hooks.insert(id, {
|
||||||
let ongoing = self.ongoing.clone();
|
let ongoing = self.ongoing.clone();
|
||||||
let (from, to) = (from.clone(), to.clone());
|
let (from, to) = (from.clone(), to.clone());
|
||||||
|
|
@ -104,6 +110,11 @@ impl Scheduler {
|
||||||
let name = format!("Copy {:?} to {:?}", from, to);
|
let name = format!("Copy {:?} to {:?}", from, to);
|
||||||
let id = self.ongoing.lock().add(TaskKind::User, name);
|
let id = self.ongoing.lock().add(TaskKind::User, name);
|
||||||
|
|
||||||
|
if to.starts_with(&from) && to != from {
|
||||||
|
self.new_and_fail(id, "Cannot copy directory into itself").ok();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let file = self.file.clone();
|
let file = self.file.clone();
|
||||||
_ = self.micro.try_send(
|
_ = self.micro.try_send(
|
||||||
async move {
|
async move {
|
||||||
|
|
@ -399,4 +410,10 @@ impl Scheduler {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn new_and_fail(&self, id: usize, reason: &str) -> Result<()> {
|
||||||
|
self.prog.send(TaskProg::New(id, 0))?;
|
||||||
|
self.prog.send(TaskProg::Fail(id, reason.to_owned()))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue