mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-07-30 04:38:44 +00:00
fix: don't remove file in get_writer; fail if target is symlink
This commit is contained in:
parent
477ec75b11
commit
91972e0300
1 changed files with 7 additions and 3 deletions
|
@ -1,10 +1,11 @@
|
|||
use crate::{async_process::async_process, profile::Profile};
|
||||
use anyhow::bail;
|
||||
use nix::{
|
||||
errno::Errno,
|
||||
sys::statvfs::{statvfs, FsFlags},
|
||||
};
|
||||
use std::{
|
||||
fs::{self, copy, create_dir_all, remove_dir_all, remove_file, File, OpenOptions},
|
||||
fs::{self, copy, create_dir_all, remove_dir_all, File, OpenOptions},
|
||||
io::{BufReader, BufWriter},
|
||||
path::Path,
|
||||
};
|
||||
|
@ -15,8 +16,11 @@ 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)?;
|
||||
if path.is_symlink() {
|
||||
bail!(
|
||||
"Provided path '{}' exists already, but it is a symlink and not a file",
|
||||
path.to_string_lossy()
|
||||
);
|
||||
}
|
||||
let file = OpenOptions::new()
|
||||
.write(true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue