1
- use std:: path:: { Path , PathBuf } ;
2
1
use std:: ffi:: CString ;
3
2
use std:: fs;
4
3
use std:: io;
4
+ use std:: path:: { Path , PathBuf } ;
5
5
6
6
// Unfortunately, on windows, it looks like msvcrt.dll is silently translating
7
7
// verbatim paths under the hood to non-verbatim paths! This manifests itself as
@@ -21,8 +21,8 @@ use std::io;
21
21
// https://github.com/rust-lang/rust/issues/25505#issuecomment-102876737
22
22
#[ cfg( windows) ]
23
23
pub fn fix_windows_verbatim_for_gcc ( p : & Path ) -> PathBuf {
24
- use std:: path;
25
24
use std:: ffi:: OsString ;
25
+ use std:: path;
26
26
let mut components = p. components ( ) ;
27
27
let prefix = match components. next ( ) {
28
28
Some ( path:: Component :: Prefix ( p) ) => p,
@@ -68,12 +68,10 @@ pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<Li
68
68
69
69
match fs:: hard_link ( p, q) {
70
70
Ok ( ( ) ) => Ok ( LinkOrCopy :: Link ) ,
71
- Err ( _) => {
72
- match fs:: copy ( p, q) {
73
- Ok ( _) => Ok ( LinkOrCopy :: Copy ) ,
74
- Err ( e) => Err ( e) ,
75
- }
76
- }
71
+ Err ( _) => match fs:: copy ( p, q) {
72
+ Ok ( _) => Ok ( LinkOrCopy :: Copy ) ,
73
+ Err ( e) => Err ( e) ,
74
+ } ,
77
75
}
78
76
}
79
77
@@ -86,29 +84,28 @@ pub enum RenameOrCopyRemove {
86
84
/// Rename `p` into `q`, preferring to use `rename` if possible.
87
85
/// If `rename` fails (rename may fail for reasons such as crossing
88
86
/// filesystem), fallback to copy & remove
89
- pub fn rename_or_copy_remove < P : AsRef < Path > , Q : AsRef < Path > > ( p : P ,
90
- q : Q )
91
- -> io:: Result < RenameOrCopyRemove > {
87
+ pub fn rename_or_copy_remove < P : AsRef < Path > , Q : AsRef < Path > > (
88
+ p : P ,
89
+ q : Q ,
90
+ ) -> io:: Result < RenameOrCopyRemove > {
92
91
let p = p. as_ref ( ) ;
93
92
let q = q. as_ref ( ) ;
94
93
match fs:: rename ( p, q) {
95
94
Ok ( ( ) ) => Ok ( RenameOrCopyRemove :: Rename ) ,
96
- Err ( _) => {
97
- match fs:: copy ( p, q) {
98
- Ok ( _) => {
99
- fs:: remove_file ( p) ?;
100
- Ok ( RenameOrCopyRemove :: CopyRemove )
101
- }
102
- Err ( e) => Err ( e) ,
95
+ Err ( _) => match fs:: copy ( p, q) {
96
+ Ok ( _) => {
97
+ fs:: remove_file ( p) ?;
98
+ Ok ( RenameOrCopyRemove :: CopyRemove )
103
99
}
104
- }
100
+ Err ( e) => Err ( e) ,
101
+ } ,
105
102
}
106
103
}
107
104
108
105
#[ cfg( unix) ]
109
106
pub fn path_to_c_string ( p : & Path ) -> CString {
110
- use std:: os:: unix:: ffi:: OsStrExt ;
111
107
use std:: ffi:: OsStr ;
108
+ use std:: os:: unix:: ffi:: OsStrExt ;
112
109
let p: & OsStr = p. as_ref ( ) ;
113
110
CString :: new ( p. as_bytes ( ) ) . unwrap ( )
114
111
}
0 commit comments