From 21cdbb41a38f465148bbeb82feb3e7886c320182 Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Mon, 9 Oct 2023 08:22:54 -0500 Subject: [PATCH] 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 --- .changes/fix-incomplete-writeFile.md | 5 +++++ core/tauri/src/endpoints/file_system.rs | 1 + 2 files changed, 6 insertions(+) create mode 100644 .changes/fix-incomplete-writeFile.md diff --git a/.changes/fix-incomplete-writeFile.md b/.changes/fix-incomplete-writeFile.md new file mode 100644 index 000000000000..4e928b59edb0 --- /dev/null +++ b/.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. \ No newline at end of file diff --git a/core/tauri/src/endpoints/file_system.rs b/core/tauri/src/endpoints/file_system.rs index 48e62f9bc564..98ea08ceba23 100644 --- a/core/tauri/src/endpoints/file_system.rs +++ b/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)