diff --git a/backend/src/handlers/mod.rs b/backend/src/handlers/mod.rs index 35b1b8f..856e18e 100644 --- a/backend/src/handlers/mod.rs +++ b/backend/src/handlers/mod.rs @@ -189,16 +189,21 @@ async fn delete_torrent_with_data( })?; // Resolve Paths (Canonicalize) to prevent .. traversal and symlink attacks - let root_path = std::fs::canonicalize(std::path::Path::new(&root_path_str)).map_err(|e| { - ( - StatusCode::INTERNAL_SERVER_ERROR, - format!("Invalid download root configuration (on server): {}", e), - ) - })?; + let root_path = tokio::fs::canonicalize(std::path::Path::new(&root_path_str)) + .await + .map_err(|e| { + ( + StatusCode::INTERNAL_SERVER_ERROR, + format!("Invalid download root configuration (on server): {}", e), + ) + })?; // Check if target path exists before trying to resolve it let target_path_raw = std::path::Path::new(&path); - if !target_path_raw.exists() { + if !tokio::fs::try_exists(target_path_raw) + .await + .unwrap_or(false) + { tracing::warn!( "Data path not found: {:?}. Removing torrent only.", target_path_raw @@ -214,12 +219,14 @@ async fn delete_torrent_with_data( return Ok("Torrent removed (Data not found)"); } - let target_path = std::fs::canonicalize(target_path_raw).map_err(|e| { - ( - StatusCode::INTERNAL_SERVER_ERROR, - format!("Invalid data path: {}", e), - ) - })?; + let target_path = tokio::fs::canonicalize(target_path_raw) + .await + .map_err(|e| { + ( + StatusCode::INTERNAL_SERVER_ERROR, + format!("Invalid data path: {}", e), + ) + })?; tracing::info!( "Delete request: Target='{:?}', Root='{:?}'", @@ -258,9 +265,9 @@ async fn delete_torrent_with_data( // 3. Delete Files via Native FS let delete_result = if target_path.is_dir() { - std::fs::remove_dir_all(&target_path) + tokio::fs::remove_dir_all(&target_path).await } else { - std::fs::remove_file(&target_path) + tokio::fs::remove_file(&target_path).await }; match delete_result { @@ -601,14 +608,18 @@ pub async fn set_global_limit_handler( if let Some(down) = payload.max_download_rate { // Convert bytes/s to KB/s (divide by 1024) let down_kb = down / 1024; - tracing::info!("Setting download limit: {} bytes/s = {} KB/s", down, down_kb); - + tracing::info!( + "Setting download limit: {} bytes/s = {} KB/s", + down, + down_kb + ); + // Use set_kb with empty string as first param (throttle name), then value if let Err(e) = client - .call("throttle.global_down.max_rate.set_kb", &[ - RpcParam::from(""), - RpcParam::Int(down_kb), - ]) + .call( + "throttle.global_down.max_rate.set_kb", + &[RpcParam::from(""), RpcParam::Int(down_kb)], + ) .await { tracing::error!("Failed to set download limit: {}", e); @@ -624,12 +635,12 @@ pub async fn set_global_limit_handler( // Convert bytes/s to KB/s let up_kb = up / 1024; tracing::info!("Setting upload limit: {} bytes/s = {} KB/s", up, up_kb); - + if let Err(e) = client - .call("throttle.global_up.max_rate.set_kb", &[ - RpcParam::from(""), - RpcParam::Int(up_kb), - ]) + .call( + "throttle.global_up.max_rate.set_kb", + &[RpcParam::from(""), RpcParam::Int(up_kb)], + ) .await { tracing::error!("Failed to set upload limit: {}", e);