mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-02 14:18:49 +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 crate::{async_process::async_process, profile::Profile};
|
||||||
|
use anyhow::bail;
|
||||||
use nix::{
|
use nix::{
|
||||||
errno::Errno,
|
errno::Errno,
|
||||||
sys::statvfs::{statvfs, FsFlags},
|
sys::statvfs::{statvfs, FsFlags},
|
||||||
};
|
};
|
||||||
use std::{
|
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},
|
io::{BufReader, BufWriter},
|
||||||
path::Path,
|
path::Path,
|
||||||
};
|
};
|
||||||
|
@ -15,8 +16,11 @@ pub fn get_writer(path: &Path) -> anyhow::Result<BufWriter<std::fs::File>> {
|
||||||
create_dir_all(parent)?;
|
create_dir_all(parent)?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if path.is_file() || path.is_symlink() {
|
if path.is_symlink() {
|
||||||
remove_file(path)?;
|
bail!(
|
||||||
|
"Provided path '{}' exists already, but it is a symlink and not a file",
|
||||||
|
path.to_string_lossy()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
let file = OpenOptions::new()
|
let file = OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue