-
Notifications
You must be signed in to change notification settings - Fork 457
Description
On Android, when selecting a file on Google Drive through the dialog plugin and obtaining a std::fs::File from the fs plugin’s tauri_plugin_fs::Fs::open, writing to it completes without any errors. But the changes are not reflected on the Google Drive side. In other words, data loss can occur with the silent error.
Reproduction
First, Create a new Tauri project. Since the code changes are only on the Rust side, the frontend config can be anything.
Second, add the following to [dependencies] in src-tauri/Cargo.toml.
tauri-plugin-fs = "2"
tauri-plugin-dialog = "2"Next, replace the entire src-tauri/lib.rs with the following.
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
async fn greet(name: &str, app: tauri::AppHandle<impl tauri::Runtime>) -> tauri::Result<String> {
use std::io::Write as _;
use tauri_plugin_fs::{FsExt as _, OpenOptions};
use tauri_plugin_dialog::DialogExt as _;
let path = app.dialog()
.file()
.set_file_name("test.txt")
.blocking_save_file();
let Some(path) = path else {
return Ok(format!("File unselected!"))
};
let mut file = app.fs().open(
path,
{
let mut option = OpenOptions::new();
option.write(true);
option
}
)?;
file.write_all("test text".as_bytes())?;
file.sync_all()?;
Ok(format!("Success"))
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_fs::init())
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}Then, build this project and install the app on an Android device or emulator. After that, make sure that the Google Drive app is installed on the device and you are signed in. Open the app and press the greet button, which will open the file saver and prompt you to select a file. At this point, select a file on Google Drive. According to the code above, test text should be written to the selected file; however, the file remains 0 bytes on Google Drive. Please also verify that if you select a file from another app or from local storage, test text is written correctly.