Browse Source

fix: truncate file when not appending in `writeFile`, closes #7973 (#7982)

* Fix https://github.com/tauri-apps/tauri/issues/7973

* Fix https://github.com/tauri-apps/tauri/issues/7973

* Fix https://github.com/tauri-apps/tauri/issues/7973
Ziyang Hu 1 year ago
parent
commit
21cdbb41a3
2 changed files with 6 additions and 0 deletions
  1. 5 0
      .changes/fix-incomplete-writeFile.md
  2. 1 0
      core/tauri/src/endpoints/file_system.rs

+ 5 - 0
.changes/fix-incomplete-writeFile.md

@@ -0,0 +1,5 @@
+---
+"tauri": 'patch:bug'
+---
+
+Set the correct `truncate` option on `OpenOptions` so that `write_file` can completely overwrite existing files.

+ 1 - 0
core/tauri/src/endpoints/file_system.rs

@@ -188,6 +188,7 @@ impl Cmd {
       .append(append)
       .append(append)
       .write(true)
       .write(true)
       .create(true)
       .create(true)
+      .truncate(!append)
       .open(&resolved_path)
       .open(&resolved_path)
       .with_context(|| format!("path: {}", resolved_path.display()))
       .with_context(|| format!("path: {}", resolved_path.display()))
       .map_err(Into::into)
       .map_err(Into::into)