Ensure Move endpoint does not overwrite an existing file #24
12
src/files.rs
12
src/files.rs
@@ -192,11 +192,21 @@ pub async fn move_file<FS: FileSystemAccess>(
|
||||
request: web::Json<MoveFileRequest>,
|
||||
) -> 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(_) => {
|
||||
|
||||
Reference in New Issue
Block a user