From 96d90c0376aba052b719fd9c2a5d9b7f061f38d5 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Thu, 28 Jul 2022 18:06:39 +1000 Subject: [PATCH] Fix `append_to_path` on windows: Use `create_if_not_exist` to open the file. Signed-off-by: Jiahao XU --- src/metafiles/binstall_v1.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/metafiles/binstall_v1.rs b/src/metafiles/binstall_v1.rs index d20ed712..5bb0e61c 100644 --- a/src/metafiles/binstall_v1.rs +++ b/src/metafiles/binstall_v1.rs @@ -95,12 +95,9 @@ pub fn append_to_path(path: impl AsRef, iter: Iter) -> Result<(), Er where Iter: IntoIterator, { - let mut file = FileLock::new_exclusive( - fs::OpenOptions::new() - .create(true) - .append(true) - .open(path)?, - )?; + let mut file = FileLock::new_exclusive(create_if_not_exist(path.as_ref())?)?; + // Move the cursor to EOF + file.seek(io::SeekFrom::End(0))?; write_to(&mut file, &mut iter.into_iter()) }