Leave special files untouched from renaming

This commit is contained in:
ByteDream 2022-12-27 20:37:45 +01:00
parent 022f23e3ab
commit 2c3bd78fc1

View file

@ -37,6 +37,12 @@ pub fn tempfile<S: AsRef<str>>(suffix: S) -> io::Result<NamedTempFile> {
/// Check if the given path exists and rename it until the new (renamed) file does not exist. /// Check if the given path exists and rename it until the new (renamed) file does not exist.
pub fn free_file(mut path: PathBuf) -> PathBuf { pub fn free_file(mut path: PathBuf) -> PathBuf {
// if path is not a file and not a dir it's probably a pipe on linux which reguarly is intended
// and thus does not need to be renamed. what it is on windows ¯\_(ツ)_/¯
if !path.is_file() && !path.is_dir() {
return path;
}
let mut i = 0; let mut i = 0;
while path.exists() { while path.exists() {
i += 1; i += 1;