From ab3f027d02d51b53ebbf92dc7accd645ada69285 Mon Sep 17 00:00:00 2001 From: Thien Tran Date: Wed, 28 May 2025 09:28:13 +0800 Subject: [PATCH] fix: support delete file for `fs.rm()` (#5117) --- src-tauri/src/core/fs.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/core/fs.rs b/src-tauri/src/core/fs.rs index 38732dfee..7b3afa8c6 100644 --- a/src-tauri/src/core/fs.rs +++ b/src-tauri/src/core/fs.rs @@ -12,8 +12,17 @@ pub fn rm(app_handle: tauri::AppHandle, args: Vec) -> Res } let path = resolve_path(app_handle, &args[0]); - fs::remove_dir_all(&path).map_err(|e| e.to_string()) + if path.is_file() { + fs::remove_file(&path).map_err(|e| e.to_string())?; + } else if path.is_dir() { + fs::remove_dir_all(&path).map_err(|e| e.to_string())?; + } else { + return Err("rm error: Path does not exist".to_string()); + } + + Ok(()) } + #[tauri::command] pub fn mkdir(app_handle: tauri::AppHandle, args: Vec) -> Result<(), String> { if args.is_empty() || args[0].is_empty() { @@ -37,6 +46,7 @@ pub fn join_path( let joined_path = path.join(args[1..].join("/")); Ok(joined_path.to_string_lossy().to_string()) } + #[tauri::command] pub fn exists_sync( app_handle: tauri::AppHandle,