tauri-apps / tauri-apps/plugins-workspace

[bug] On Android, writing to a file on Google Drive does not occur, and no error is raised

Open
#3,109 3 comments 0 reactions 0 assignees View on GitHub
platform: android plugin: fs type: bug type: feature request
Dominant language
Rust
Stars
1.8k
Forks
602
Avg merge
4d 14h
Merged PRs (30d)
9

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`](https://docs.rs/tauri-plugin-fs/2.4.4/tauri_plugin_fs/struct.Fs.html#method.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`.
```toml
tauri-plugin-fs = "2"
tauri-plugin-dialog = "2"
```

Next, replace the entire `src-tauri/lib.rs` with the following.

```rust
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
async fn greet(name: &str, app: tauri::AppHandle) -> tauri::Result {
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.