1
- #[ cfg( windows_by_handle) ]
2
- use super :: get_path:: concatenate;
3
1
use crate :: fs:: { FollowSymlinks , Metadata } ;
4
2
use std:: path:: Path ;
5
3
use std:: { fs, io} ;
6
- #[ cfg( not( windows_by_handle) ) ]
7
- use windows_sys:: Win32 :: Storage :: FileSystem :: {
8
- FILE_FLAG_BACKUP_SEMANTICS , FILE_FLAG_OPEN_REPARSE_POINT ,
9
- } ;
10
- #[ cfg( not( windows_by_handle) ) ]
11
4
use {
12
5
crate :: fs:: { open_unchecked, OpenOptions } ,
13
6
std:: os:: windows:: fs:: OpenOptionsExt ,
7
+ windows_sys:: Win32 :: Storage :: FileSystem :: {
8
+ FILE_FLAG_BACKUP_SEMANTICS , FILE_FLAG_OPEN_REPARSE_POINT ,
9
+ } ,
14
10
} ;
15
11
16
12
/// *Unsandboxed* function similar to `stat`, but which does not perform
@@ -20,35 +16,24 @@ pub(crate) fn stat_unchecked(
20
16
path : & Path ,
21
17
follow : FollowSymlinks ,
22
18
) -> io:: Result < Metadata > {
23
- // When we have `windows_by_handle`, we just call `fs::metadata` etc. and it
24
- // has everything.
25
- #[ cfg( windows_by_handle) ]
26
- {
27
- let full_path = concatenate ( start, path) ?;
28
- match follow {
29
- FollowSymlinks :: Yes => fs:: metadata ( full_path) ,
30
- FollowSymlinks :: No => fs:: symlink_metadata ( full_path) ,
31
- }
32
- . map ( Metadata :: from_just_metadata)
33
- }
19
+ // Attempt to open the file to get the metadata that way, as that gives
20
+ // us all the info.
21
+ let mut opts = OpenOptions :: new ( ) ;
34
22
35
- // Otherwise, attempt to open the file to get the metadata that way, as
36
- // that gives us all the info.
37
- #[ cfg( not( windows_by_handle) ) ]
38
- {
39
- let mut opts = OpenOptions :: new ( ) ;
40
- opts. access_mode ( 0 ) ;
41
- match follow {
42
- FollowSymlinks :: Yes => {
43
- opts. custom_flags ( FILE_FLAG_BACKUP_SEMANTICS ) ;
44
- opts. follow ( FollowSymlinks :: Yes ) ;
45
- }
46
- FollowSymlinks :: No => {
47
- opts. custom_flags ( FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS ) ;
48
- opts. follow ( FollowSymlinks :: No ) ;
49
- }
23
+ // Explicitly request no access, because we're just querying metadata.
24
+ opts. access_mode ( 0 ) ;
25
+
26
+ match follow {
27
+ FollowSymlinks :: Yes => {
28
+ opts. custom_flags ( FILE_FLAG_BACKUP_SEMANTICS ) ;
29
+ opts. follow ( FollowSymlinks :: Yes ) ;
30
+ }
31
+ FollowSymlinks :: No => {
32
+ opts. custom_flags ( FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS ) ;
33
+ opts. follow ( FollowSymlinks :: No ) ;
50
34
}
51
- let file = open_unchecked ( start, path, & opts) ?;
52
- Metadata :: from_file ( & file)
53
35
}
36
+
37
+ let file = open_unchecked ( start, path, & opts) ?;
38
+ Metadata :: from_file ( & file)
54
39
}
0 commit comments