From 0c186644191b29f11c07f5de0be76d76a10f1a81 Mon Sep 17 00:00:00 2001 From: rolv Date: Thu, 18 Apr 2024 11:22:19 +0100 Subject: [PATCH] fix: use easier method of determining if path is subdirectory of itself --- yazi-scheduler/src/file/file.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/yazi-scheduler/src/file/file.rs b/yazi-scheduler/src/file/file.rs index 0f69eeaa..a036faaa 100644 --- a/yazi-scheduler/src/file/file.rs +++ b/yazi-scheduler/src/file/file.rs @@ -135,18 +135,12 @@ impl File { pub async fn paste(&self, mut task: FileOpPaste) -> Result<()> { // Prevent pasting of a directory into itself - if task.from.is_dir() { - let mut parent = task.to.parent_url(); - while let Some(p) = parent { - if task.from == p { - debug!( - "file_paste: cannot paste directory into itself, skipping {:?} -> {:?}", - task.from, task.to - ); - return self.succ(task.id); - } - parent = p.parent_url(); - } + if task.from.is_dir() && task.to.as_path().starts_with(task.from.as_path()) { + debug!( + "file_paste: cannot paste directory into itself, skipping {:?} -> {:?}", + task.from, task.to + ); + return self.succ(task.id); } if task.cut {