diff --git a/runtime/src/file_actions.rs b/runtime/src/file_actions.rs index b917158f..41ceeeab 100644 --- a/runtime/src/file_actions.rs +++ b/runtime/src/file_actions.rs @@ -323,16 +323,38 @@ pub async fn open_path_in_file_manager( }); } - let Some(target) = resolve_file_manager_target(&requested_path) else { + match open_file_manager_target(&requested_path).await { + Ok(()) => Json(OpenPathResponse { + success: true, + issue: String::new(), + }), + + Err(issue) => { + error!(Source = "Tauri"; "{issue}"); + Json(OpenPathResponse { + success: false, + issue, + }) + } + } +} + +#[cfg(target_os = "linux")] +pub(crate) async fn open_existing_file_in_file_manager(path: PathBuf) -> Result<(), String> { + if !path.is_file() { + return Err(format!("The requested path is not an existing file: {}", path.to_string_lossy())); + } + + open_file_manager_target(&path).await +} + +async fn open_file_manager_target(requested_path: &Path) -> Result<(), String> { + let Some(target) = resolve_file_manager_target(requested_path) else { let issue = format!( "The path does not exist and its parent folder could not be found: {}", requested_path.to_string_lossy(), ); - error!(Source = "Tauri"; "{issue}"); - return Json(OpenPathResponse { - success: false, - issue, - }); + return Err(issue); }; #[cfg(target_os = "linux")] @@ -340,19 +362,10 @@ pub async fn open_path_in_file_manager( return match open_path_in_linux_file_manager(&target).await { Ok(()) => { info!("Opened file manager for path: {:?}", target.path); - Json(OpenPathResponse { - success: true, - issue: String::new(), - }) + Ok(()) } - Err(issue) => { - error!(Source = "Tauri"; "{issue}"); - Json(OpenPathResponse { - success: false, - issue, - }) - } + Err(issue) => Err(issue), }; } @@ -366,19 +379,12 @@ pub async fn open_path_in_file_manager( match command.spawn() { Ok(_) => { info!("Opened file manager for path: {:?}", target.path); - Json(OpenPathResponse { - success: true, - issue: String::new(), - }) + Ok(()) } Err(error) => { let issue = format!("Failed to open the file manager: {error}"); - error!(Source = "Tauri"; "{issue}"); - Json(OpenPathResponse { - success: false, - issue, - }) + Err(issue) } } }