瀏覽代碼

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 年之前
父節點
當前提交
21cdbb41a3
共有 2 個文件被更改,包括 6 次插入0 次删除
  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)
       .write(true)
       .create(true)
+      .truncate(!append)
       .open(&resolved_path)
       .with_context(|| format!("path: {}", resolved_path.display()))
       .map_err(Into::into)