@@ -109,6 +109,60 @@ use libc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, st
109
109
110
110
pub use crate :: sys_common:: fs:: try_exists;
111
111
112
+ pub ( crate ) mod fs_imp {
113
+ use crate :: io;
114
+ use crate :: path:: AsPath ;
115
+ use crate :: path:: PathBuf ;
116
+ use crate :: sys:: fs;
117
+ pub ( crate ) use crate :: sys:: fs:: {
118
+ DirBuilder , DirEntry , File , FileAttr , FilePermissions , FileTimes , FileType , OpenOptions ,
119
+ ReadDir ,
120
+ } ;
121
+
122
+ pub ( crate ) fn remove_file < P : AsPath > ( path : P ) -> io:: Result < ( ) > {
123
+ path. with_path ( fs:: unlink)
124
+ }
125
+ pub ( crate ) fn symlink_metadata < P : AsPath > ( path : P ) -> io:: Result < FileAttr > {
126
+ path. with_path ( |path| fs:: lstat ( path) )
127
+ }
128
+ pub ( crate ) fn metadata < P : AsPath > ( path : P ) -> io:: Result < FileAttr > {
129
+ path. with_path ( |path| fs:: stat ( path) )
130
+ }
131
+ pub ( crate ) fn rename < P : AsPath , Q : AsPath > ( from : P , to : Q ) -> io:: Result < ( ) > {
132
+ from. with_path ( |from| to. with_path ( |to| fs:: rename ( from, to) ) )
133
+ }
134
+ pub ( crate ) fn hard_link < P : AsPath , Q : AsPath > ( original : P , link : Q ) -> io:: Result < ( ) > {
135
+ original. with_path ( |original| link. with_path ( |link| fs:: link ( original, link) ) )
136
+ }
137
+ pub ( crate ) fn soft_link < P : AsPath , Q : AsPath > ( original : P , link : Q ) -> io:: Result < ( ) > {
138
+ original. with_path ( |original| link. with_path ( |link| fs:: symlink ( original, link) ) )
139
+ }
140
+ pub ( crate ) fn remove_dir < P : AsPath > ( path : P ) -> io:: Result < ( ) > {
141
+ path. with_path ( fs:: rmdir)
142
+ }
143
+ pub ( crate ) fn read_dir < P : AsPath > ( path : P ) -> io:: Result < ReadDir > {
144
+ path. with_path ( fs:: readdir)
145
+ }
146
+ pub ( crate ) fn set_permissions < P : AsPath > ( path : P , perms : FilePermissions ) -> io:: Result < ( ) > {
147
+ path. with_path ( |path| fs:: set_perm ( path, perms) )
148
+ }
149
+ pub ( crate ) fn copy < P : AsPath , Q : AsPath > ( from : P , to : Q ) -> io:: Result < u64 > {
150
+ from. with_path ( |from| to. with_path ( |to| fs:: copy ( from, to) ) )
151
+ }
152
+ pub ( crate ) fn canonicalize < P : AsPath > ( path : P ) -> io:: Result < PathBuf > {
153
+ path. with_path ( fs:: canonicalize)
154
+ }
155
+ pub ( crate ) fn remove_dir_all < P : AsPath > ( path : P ) -> io:: Result < ( ) > {
156
+ path. with_path ( fs:: remove_dir_all)
157
+ }
158
+ pub ( crate ) fn read_link < P : AsPath > ( path : P ) -> io:: Result < PathBuf > {
159
+ path. with_path ( fs:: readlink)
160
+ }
161
+ pub ( crate ) fn try_exists < P : AsPath > ( path : P ) -> io:: Result < bool > {
162
+ path. with_path ( fs:: try_exists)
163
+ }
164
+ }
165
+
112
166
pub struct File ( FileDesc ) ;
113
167
114
168
// FIXME: This should be available on Linux with all `target_env`.
@@ -1117,11 +1171,7 @@ impl OpenOptions {
1117
1171
}
1118
1172
1119
1173
impl File {
1120
- pub fn open ( path : & Path , opts : & OpenOptions ) -> io:: Result < File > {
1121
- run_path_with_cstr ( path, & |path| File :: open_c ( path, opts) )
1122
- }
1123
-
1124
- pub fn open_c ( path : & CStr , opts : & OpenOptions ) -> io:: Result < File > {
1174
+ pub fn open_native ( path : & CStr , opts : & OpenOptions ) -> io:: Result < File > {
1125
1175
let flags = libc:: O_CLOEXEC
1126
1176
| opts. get_access_mode ( ) ?
1127
1177
| opts. get_creation_mode ( ) ?
0 commit comments