fix: get_writer removes file if it exists
Some checks are pending
/ cargo-fmtcheck (push) Waiting to run
/ cargo-clippy (push) Waiting to run
/ cargo-test (push) Waiting to run
/ appimage (push) Waiting to run

This commit is contained in:
Gabriele Musco 2024-09-27 23:54:00 +02:00
parent deed33bb0f
commit 8341183820
No known key found for this signature in database
GPG key ID: 1068D795C80E51DE

View file

@ -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<BufWriter<std::fs::File>> {
create_dir_all(parent)?;
}
};
if path.is_file() || path.is_symlink() {
remove_file(path)?;
}
let file = OpenOptions::new()
.write(true)
.create(true)