fix: use easier method of determining if path is subdirectory of itself

This commit is contained in:
rolv 2024-04-18 11:22:19 +01:00 committed by sxyazi
parent ae13c29488
commit 0c18664419
No known key found for this signature in database

View file

@ -135,18 +135,12 @@ impl File {
pub async fn paste(&self, mut task: FileOpPaste) -> Result<()> { pub async fn paste(&self, mut task: FileOpPaste) -> Result<()> {
// Prevent pasting of a directory into itself // Prevent pasting of a directory into itself
if task.from.is_dir() { if task.from.is_dir() && task.to.as_path().starts_with(task.from.as_path()) {
let mut parent = task.to.parent_url(); debug!(
while let Some(p) = parent { "file_paste: cannot paste directory into itself, skipping {:?} -> {:?}",
if task.from == p { task.from, task.to
debug!( );
"file_paste: cannot paste directory into itself, skipping {:?} -> {:?}", return self.succ(task.id);
task.from, task.to
);
return self.succ(task.id);
}
parent = p.parent_url();
}
} }
if task.cut { if task.cut {