5
5
6
6
use std:: fs:: File ;
7
7
use std:: io;
8
- #[ cfg( target_os = "linux" ) ]
9
- use std:: path:: Path ;
10
8
use std:: path:: PathBuf ;
11
9
12
- #[ cfg( target_os = "linux" ) ]
13
- use std:: fs:: read_link;
14
-
15
10
#[ cfg( unix) ]
16
11
use std:: os:: unix:: io:: AsRawFd ;
17
- #[ cfg( windows) ]
18
- use std:: os:: windows:: io:: AsRawHandle ;
19
-
20
- #[ cfg( any( target_os = "macos" , target_os = "ios" , windows) ) ]
21
- use std:: ffi:: OsString ;
22
-
23
- #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
24
- use std:: os:: unix:: ffi:: OsStringExt ;
25
- #[ cfg( windows) ]
26
- use std:: os:: windows:: prelude:: * ;
27
-
28
- #[ cfg( windows) ]
29
- use windows:: Win32 :: {
30
- Foundation ,
31
- Storage :: FileSystem :: { GetFinalPathNameByHandleW , GETFINALPATHNAMEBYHANDLE_FLAGS } ,
32
- } ;
33
-
34
- #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
35
- const F_GETPATH : i32 = 50 ;
36
12
37
13
/// An extension trait for `std::fs::File` providing a `path` method.
38
14
pub trait FilePath {
@@ -63,13 +39,19 @@ pub trait FilePath {
63
39
impl FilePath for File {
64
40
#[ cfg( target_os = "linux" ) ]
65
41
fn path ( & self ) -> io:: Result < PathBuf > {
42
+ use std:: path:: Path ;
43
+
66
44
let fd = self . as_raw_fd ( ) ;
67
45
let path = Path :: new ( "/proc/self/fd/" ) . join ( fd. to_string ( ) ) ;
68
- read_link ( path)
46
+ std :: fs :: read_link ( path)
69
47
}
70
48
71
49
#[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
72
50
fn path ( & self ) -> io:: Result < PathBuf > {
51
+ use std:: ffi:: OsString ;
52
+ use std:: os:: unix:: ffi:: OsStringExt ;
53
+ const F_GETPATH : i32 = 50 ;
54
+
73
55
let fd = self . as_raw_fd ( ) ;
74
56
let mut path = vec ! [ 0 ; libc:: PATH_MAX as usize + 1 ] ;
75
57
@@ -84,7 +66,13 @@ impl FilePath for File {
84
66
}
85
67
86
68
#[ cfg( windows) ]
87
- fn path ( & self ) -> io:: Result < PathBuf > {
69
+ fn path ( & self ) -> std:: io:: Result < PathBuf > {
70
+ use std:: os:: windows:: { ffi:: OsStringExt , io:: AsRawHandle } ;
71
+ use windows:: Win32 :: {
72
+ Foundation ,
73
+ Storage :: FileSystem :: { GetFinalPathNameByHandleW , GETFINALPATHNAMEBYHANDLE_FLAGS } ,
74
+ } ;
75
+
88
76
// Call with null to get the required size.
89
77
let len = unsafe {
90
78
let handle = Foundation :: HANDLE ( self . as_raw_handle ( ) ) ;
0 commit comments