From 32d8077dd40dcabf305f21a881a4e02438407a3a Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Sun, 8 Oct 2023 15:41:15 +0800 Subject: [PATCH] Fix incomplete overwriting behaviour in fs.writeFile. This contains the same fix as https://github.com/tauri-apps/tauri/pull/7982 which fixes https://github.com/tauri-apps/tauri/issues/7973 But as v2 moves things around a little bit the fix is necessary here as well. --- plugins/fs/src/commands.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/fs/src/commands.rs b/plugins/fs/src/commands.rs index 59255796..8cf7d51b 100644 --- a/plugins/fs/src/commands.rs +++ b/plugins/fs/src/commands.rs @@ -117,9 +117,9 @@ pub fn write_file( .with_context(|| format!("path: {}", resolved_path.display())) .map_err(Into::into) .and_then(|mut f| { - f.write_all(&contents) - .map_err(|err| anyhow::anyhow!("{}", err)) - .map_err(Into::into) + f.write_all(&contents).map_err(|err| anyhow::anyhow!("{}", err))?; + f.set_len(contents.len() as u64).map_err(|err| anyhow::anyhow!("{}", err))?; + Ok(()) }) }