1- use std:: path:: { Path , PathBuf } ;
21use std:: ffi:: CString ;
32use std:: fs;
43use std:: io;
4+ use std:: path:: { Path , PathBuf } ;
55
66// Unfortunately, on windows, it looks like msvcrt.dll is silently translating
77// verbatim paths under the hood to non-verbatim paths! This manifests itself as
@@ -21,8 +21,8 @@ use std::io;
2121// https://github.com/rust-lang/rust/issues/25505#issuecomment-102876737
2222#[ cfg( windows) ]
2323pub fn fix_windows_verbatim_for_gcc ( p : & Path ) -> PathBuf {
24- use std:: path;
2524 use std:: ffi:: OsString ;
25+ use std:: path;
2626 let mut components = p. components ( ) ;
2727 let prefix = match components. next ( ) {
2828 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
6868
6969 match fs:: hard_link ( p, q) {
7070 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+ } ,
7775 }
7876}
7977
@@ -86,29 +84,28 @@ pub enum RenameOrCopyRemove {
8684/// Rename `p` into `q`, preferring to use `rename` if possible.
8785/// If `rename` fails (rename may fail for reasons such as crossing
8886/// 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 > {
9291 let p = p. as_ref ( ) ;
9392 let q = q. as_ref ( ) ;
9493 match fs:: rename ( p, q) {
9594 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 )
10399 }
104- }
100+ Err ( e) => Err ( e) ,
101+ } ,
105102 }
106103}
107104
108105#[ cfg( unix) ]
109106pub fn path_to_c_string ( p : & Path ) -> CString {
110- use std:: os:: unix:: ffi:: OsStrExt ;
111107 use std:: ffi:: OsStr ;
108+ use std:: os:: unix:: ffi:: OsStrExt ;
112109 let p: & OsStr = p. as_ref ( ) ;
113110 CString :: new ( p. as_bytes ( ) ) . unwrap ( )
114111}
0 commit comments