diff --git a/src/files.rs b/src/files.rs index a46b026..94d2347 100644 --- a/src/files.rs +++ b/src/files.rs @@ -192,11 +192,21 @@ pub async fn move_file( request: web::Json, ) -> HttpResponse { match is_valid_full_path(&app_state.base_path, &request.source, false) + .ok_or(ErrorKind::InvalidData) .and_then(|source| { is_valid_full_path(&app_state.base_path, &request.destination, true) + .ok_or(ErrorKind::InvalidData) + .and_then(|dest| { + if dest.exists() { + error!("Destination already exists, not moving file: {:?}", source); + + Err(ErrorKind::AlreadyExists) + } else { + Ok(dest) + } + }) .map(|dest| (source, dest)) }) - .ok_or(ErrorKind::InvalidData) .map(|(source, dest)| file_system.move_file(source, dest)) { Ok(_) => {