diff --git a/plugins/fs/src/commands.rs b/plugins/fs/src/commands.rs index 719178c6..ceecac99 100644 --- a/plugins/fs/src/commands.rs +++ b/plugins/fs/src/commands.rs @@ -342,8 +342,7 @@ pub async fn read( Ok(tauri::ipc::Response::new(data)) } -#[tauri::command] -pub async fn read_file( +async fn read_file_inner( webview: Webview, global_scope: GlobalScope, command_scope: CommandScope, @@ -379,6 +378,17 @@ pub async fn read_file( Ok(tauri::ipc::Response::new(contents)) } +#[tauri::command] +pub async fn read_file( + webview: Webview, + global_scope: GlobalScope, + command_scope: CommandScope, + path: SafeFilePath, + options: Option, +) -> CommandResult { + read_file_inner("read-file", global_scope, command_scope, path, options).await +} + // TODO, remove in v3, rely on `read_file` command instead #[tauri::command] pub async fn read_text_file( @@ -388,33 +398,7 @@ pub async fn read_text_file( path: SafeFilePath, options: Option, ) -> CommandResult { - let (mut file, path) = resolve_file( - "read-text-file", - &webview, - &global_scope, - &command_scope, - path, - OpenOptions { - base: BaseOptions { - base_dir: options.as_ref().and_then(|o| o.base_dir), - }, - options: crate::OpenOptions { - read: true, - ..Default::default() - }, - }, - )?; - - let mut contents = Vec::new(); - - file.read_to_end(&mut contents).map_err(|e| { - format!( - "failed to read file as text at path: {} with error: {e}", - path.display() - ) - })?; - - Ok(tauri::ipc::Response::new(contents)) + read_file_inner("read-text-file", global_scope, command_scope, path, options).await } #[tauri::command]