From 8341183820628232b83b3c70a91cc57405e37023 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Fri, 27 Sep 2024 23:54:00 +0200 Subject: [PATCH] fix: get_writer removes file if it exists --- src/util/file_utils.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/file_utils.rs b/src/util/file_utils.rs index 7812ef1..45a6e96 100644 --- a/src/util/file_utils.rs +++ b/src/util/file_utils.rs @@ -4,7 +4,7 @@ use nix::{ sys::statvfs::{statvfs, FsFlags}, }; use std::{ - fs::{self, copy, create_dir_all, remove_dir_all, File, OpenOptions}, + fs::{self, copy, create_dir_all, remove_dir_all, remove_file, File, OpenOptions}, io::{BufReader, BufWriter}, path::Path, }; @@ -15,6 +15,9 @@ pub fn get_writer(path: &Path) -> anyhow::Result> { create_dir_all(parent)?; } }; + if path.is_file() || path.is_symlink() { + remove_file(path)?; + } let file = OpenOptions::new() .write(true) .create(true)