use std::{io, io::ErrorKind::AlreadyExists, path::Path};
#[cfg(not(windows))]
pub fn create(original: &Path, link: &Path) -> io::Result<()> {
std::os::unix::fs::symlink(original, link)
}
#[cfg(not(windows))]
pub fn remove(path: &Path) -> io::Result<()> {
std::fs::remove_file(path)
}
#[cfg(windows)]
pub fn remove(path: &Path) -> io::Result<()> {
if let Ok(meta) = std::fs::metadata(path) {
if meta.is_file() {
std::fs::remove_file(path) } else {
std::fs::remove_dir(path) }
} else {
std::fs::remove_file(path).or_else(|_| std::fs::remove_dir(path))
}
}
#[cfg(windows)]
pub fn create(original: &Path, link: &Path) -> io::Result<()> {
use std::os::windows::fs::{symlink_dir, symlink_file};
if std::fs::metadata(link.parent().expect("dir for link").join(original))?.is_dir() {
symlink_dir(original, link)
} else {
symlink_file(original, link)
}
}
#[cfg(not(windows))]
pub fn is_collision_error(err: &std::io::Error) -> bool {
err.kind() == AlreadyExists
|| err.raw_os_error() == Some(21)
|| err.raw_os_error() == Some(62) || err.raw_os_error() == Some(40) }
#[cfg(windows)]
pub fn is_collision_error(err: &std::io::Error) -> bool {
err.kind() == AlreadyExists || err.kind() == std::io::ErrorKind::PermissionDenied
}