1
1
use std:: { io, io:: ErrorKind :: AlreadyExists , path:: Path } ;
2
2
3
- #[ cfg( not( windows) ) ]
4
3
/// Create a new symlink at `link` which points to `original`.
5
4
///
6
5
/// Note that `original` doesn't have to exist.
6
+ #[ cfg( not( windows) ) ]
7
7
pub fn create ( original : & Path , link : & Path ) -> io:: Result < ( ) > {
8
8
std:: os:: unix:: fs:: symlink ( original, link)
9
9
}
10
10
11
- #[ cfg( not( windows) ) ]
12
11
/// Remove a symlink.
13
12
///
14
13
/// Note that on only on windows this is special.
14
+ #[ cfg( not( windows) ) ]
15
15
pub fn remove ( path : & Path ) -> io:: Result < ( ) > {
16
16
std:: fs:: remove_file ( path)
17
17
}
@@ -31,12 +31,12 @@ pub fn remove(path: &Path) -> io::Result<()> {
31
31
}
32
32
}
33
33
34
- #[ cfg( windows) ]
35
34
/// Create a new symlink at `link` which points to `original`.
36
35
///
37
36
/// Note that if a symlink target (the `original`) isn't present on disk, it's assumed to be a
38
37
/// file, creating a dangling file symlink. This is similar to a dangling symlink on Unix,
39
38
/// which doesn't have to care about the target type though.
39
+ #[ cfg( windows) ]
40
40
pub fn create ( original : & Path , link : & Path ) -> io:: Result < ( ) > {
41
41
use std:: os:: windows:: fs:: { symlink_dir, symlink_file} ;
42
42
// 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<()> {
53
53
}
54
54
}
55
55
56
- #[ cfg( not( windows) ) ]
57
56
/// Return true if `err` indicates that a file collision happened, i.e. a symlink couldn't be created as the `link`
58
57
/// already exists as filesystem object.
58
+ #[ cfg( not( windows) ) ]
59
59
pub fn is_collision_error ( err : & std:: io:: Error ) -> bool {
60
60
// TODO: use ::IsDirectory as well when stabilized instead of raw_os_error(), and ::FileSystemLoop respectively
61
61
err. kind ( ) == AlreadyExists
62
- || err. raw_os_error ( ) == Some ( if cfg ! ( windows ) { 5 } else { 21 } )
62
+ || err. raw_os_error ( ) == Some ( 21 )
63
63
|| err. raw_os_error ( ) == Some ( 62 ) // no-follow on symlnk on mac-os
64
64
|| err. raw_os_error ( ) == Some ( 40 ) // no-follow on symlnk on ubuntu
65
65
}
66
66
67
- #[ cfg( windows) ]
68
67
/// Return true if `err` indicates that a file collision happened, i.e. a symlink couldn't be created as the `link`
69
68
/// already exists as filesystem object.
69
+ #[ cfg( windows) ]
70
70
pub fn is_collision_error ( err : & std:: io:: Error ) -> bool {
71
71
err. kind ( ) == AlreadyExists || err. kind ( ) == std:: io:: ErrorKind :: PermissionDenied
72
72
}
0 commit comments