Fix append_to_path on windows: Use create_if_not_exist

to open the file.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-07-28 18:06:39 +10:00
parent 3f72e9b81a
commit 96d90c0376
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -95,12 +95,9 @@ pub fn append_to_path<Iter>(path: impl AsRef<Path>, iter: Iter) -> Result<(), Er
where
Iter: IntoIterator<Item = MetaData>,
{
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())
}