Skip to content

Commit bb7129f

Browse files
committed
avoid condition that is always false in is_collision_error
1 parent 2cefe77 commit bb7129f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

gix-fs/src/symlink.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use std::{io, io::ErrorKind::AlreadyExists, path::Path};
22

3-
#[cfg(not(windows))]
43
/// Create a new symlink at `link` which points to `original`.
54
///
65
/// Note that `original` doesn't have to exist.
6+
#[cfg(not(windows))]
77
pub fn create(original: &Path, link: &Path) -> io::Result<()> {
88
std::os::unix::fs::symlink(original, link)
99
}
1010

11-
#[cfg(not(windows))]
1211
/// Remove a symlink.
1312
///
1413
/// Note that on only on windows this is special.
14+
#[cfg(not(windows))]
1515
pub fn remove(path: &Path) -> io::Result<()> {
1616
std::fs::remove_file(path)
1717
}
@@ -31,12 +31,12 @@ pub fn remove(path: &Path) -> io::Result<()> {
3131
}
3232
}
3333

34-
#[cfg(windows)]
3534
/// Create a new symlink at `link` which points to `original`.
3635
///
3736
/// Note that if a symlink target (the `original`) isn't present on disk, it's assumed to be a
3837
/// file, creating a dangling file symlink. This is similar to a dangling symlink on Unix,
3938
/// which doesn't have to care about the target type though.
39+
#[cfg(windows)]
4040
pub fn create(original: &Path, link: &Path) -> io::Result<()> {
4141
use std::os::windows::fs::{symlink_dir, symlink_file};
4242
// TODO: figure out if links to links count as files or whatever they point at
@@ -53,20 +53,20 @@ pub fn create(original: &Path, link: &Path) -> io::Result<()> {
5353
}
5454
}
5555

56-
#[cfg(not(windows))]
5756
/// Return true if `err` indicates that a file collision happened, i.e. a symlink couldn't be created as the `link`
5857
/// already exists as filesystem object.
58+
#[cfg(not(windows))]
5959
pub fn is_collision_error(err: &std::io::Error) -> bool {
6060
// TODO: use ::IsDirectory as well when stabilized instead of raw_os_error(), and ::FileSystemLoop respectively
6161
err.kind() == AlreadyExists
62-
|| err.raw_os_error() == Some(if cfg!(windows) { 5 } else { 21 })
62+
|| err.raw_os_error() == Some(21)
6363
|| err.raw_os_error() == Some(62) // no-follow on symlnk on mac-os
6464
|| err.raw_os_error() == Some(40) // no-follow on symlnk on ubuntu
6565
}
6666

67-
#[cfg(windows)]
6867
/// Return true if `err` indicates that a file collision happened, i.e. a symlink couldn't be created as the `link`
6968
/// already exists as filesystem object.
69+
#[cfg(windows)]
7070
pub fn is_collision_error(err: &std::io::Error) -> bool {
7171
err.kind() == AlreadyExists || err.kind() == std::io::ErrorKind::PermissionDenied
7272
}

0 commit comments

Comments
 (0)