@@ -11,6 +11,7 @@ use crate::ptr;
11
11
use crate :: slice;
12
12
use crate :: sync:: Arc ;
13
13
use crate :: sys:: handle:: Handle ;
14
+ use crate :: sys:: path:: NativePath ;
14
15
use crate :: sys:: time:: SystemTime ;
15
16
use crate :: sys:: { c, cvt, Align8 } ;
16
17
use crate :: sys_common:: { AsInner , FromInner , IntoInner } ;
@@ -19,6 +20,60 @@ use crate::thread;
19
20
use super :: { api, to_u16s, IoResult } ;
20
21
use crate :: sys:: path:: maybe_verbatim;
21
22
23
+ /// The crate-public interface
24
+ pub ( crate ) mod fs_imp {
25
+ use crate :: io;
26
+ use crate :: path:: AsPath ;
27
+ use crate :: path:: PathBuf ;
28
+ use crate :: sys:: fs;
29
+ pub ( crate ) use crate :: sys:: fs:: {
30
+ DirBuilder , DirEntry , File , FileAttr , FilePermissions , FileTimes , FileType , OpenOptions ,
31
+ ReadDir ,
32
+ } ;
33
+ pub ( crate ) fn remove_file < P : AsPath > ( path : P ) -> io:: Result < ( ) > {
34
+ path. with_path ( fs:: unlink)
35
+ }
36
+ pub ( crate ) fn symlink_metadata < P : AsPath > ( path : P ) -> io:: Result < FileAttr > {
37
+ path. with_path ( fs:: lstat)
38
+ }
39
+ pub ( crate ) fn metadata < P : AsPath > ( path : P ) -> io:: Result < FileAttr > {
40
+ path. with_path ( fs:: stat)
41
+ }
42
+ pub ( crate ) fn rename < P : AsPath , Q : AsPath > ( from : P , to : Q ) -> io:: Result < ( ) > {
43
+ from. with_path ( |from| to. with_path ( |to| fs:: rename ( from, to) ) )
44
+ }
45
+ pub ( crate ) fn hard_link < P : AsPath , Q : AsPath > ( original : P , link : Q ) -> io:: Result < ( ) > {
46
+ original. with_path ( |original| link. with_path ( |link| fs:: link ( original, link) ) )
47
+ }
48
+ pub ( crate ) fn soft_link < P : AsPath , Q : AsPath > ( original : P , link : Q ) -> io:: Result < ( ) > {
49
+ original. with_path ( |original| link. with_path ( |link| fs:: symlink ( original, link) ) )
50
+ }
51
+ pub ( crate ) fn remove_dir < P : AsPath > ( path : P ) -> io:: Result < ( ) > {
52
+ path. with_path ( fs:: rmdir)
53
+ }
54
+ pub ( crate ) fn read_dir < P : AsPath > ( path : P ) -> io:: Result < ReadDir > {
55
+ path. with_path ( fs:: readdir)
56
+ }
57
+ pub ( crate ) fn set_permissions < P : AsPath > ( path : P , perms : FilePermissions ) -> io:: Result < ( ) > {
58
+ path. with_path ( |path| fs:: set_perm ( path, perms) )
59
+ }
60
+ pub ( crate ) fn copy < P : AsPath , Q : AsPath > ( from : P , to : Q ) -> io:: Result < u64 > {
61
+ from. with_path ( |from| to. with_path ( |to| fs:: copy ( from, to) ) )
62
+ }
63
+ pub ( crate ) fn canonicalize < P : AsPath > ( path : P ) -> io:: Result < PathBuf > {
64
+ path. with_path ( fs:: canonicalize)
65
+ }
66
+ pub ( crate ) fn remove_dir_all < P : AsPath > ( path : P ) -> io:: Result < ( ) > {
67
+ path. with_path ( fs:: remove_dir_all)
68
+ }
69
+ pub ( crate ) fn read_link < P : AsPath > ( path : P ) -> io:: Result < PathBuf > {
70
+ path. with_path ( fs:: readlink)
71
+ }
72
+ pub ( crate ) fn try_exists < P : AsPath > ( path : P ) -> io:: Result < bool > {
73
+ path. with_path ( fs:: try_exists)
74
+ }
75
+ }
76
+
22
77
pub struct File {
23
78
handle : Handle ,
24
79
}
@@ -294,8 +349,12 @@ impl OpenOptions {
294
349
}
295
350
296
351
impl File {
297
- pub fn open ( path : & Path , opts : & OpenOptions ) -> io:: Result < File > {
352
+ pub ( super ) fn open ( path : & Path , opts : & OpenOptions ) -> io:: Result < File > {
298
353
let path = maybe_verbatim ( path) ?;
354
+ let path = unsafe { NativePath :: new_unchecked ( & path) } ;
355
+ Self :: open_native ( path, opts)
356
+ }
357
+ pub fn open_native ( path : & NativePath , opts : & OpenOptions ) -> io:: Result < File > {
299
358
let creation = opts. get_creation_mode ( ) ?;
300
359
let handle = unsafe {
301
360
c:: CreateFileW (
0 commit comments