1- #[ cfg( windows_by_handle) ]
2- use super :: get_path:: concatenate;
31use crate :: fs:: { FollowSymlinks , Metadata } ;
42use std:: path:: Path ;
53use 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) ) ]
114use {
125 crate :: fs:: { open_unchecked, OpenOptions } ,
136 std:: os:: windows:: fs:: OpenOptionsExt ,
7+ windows_sys:: Win32 :: Storage :: FileSystem :: {
8+ FILE_FLAG_BACKUP_SEMANTICS , FILE_FLAG_OPEN_REPARSE_POINT ,
9+ } ,
1410} ;
1511
1612/// *Unsandboxed* function similar to `stat`, but which does not perform
@@ -20,35 +16,24 @@ pub(crate) fn stat_unchecked(
2016 path : & Path ,
2117 follow : FollowSymlinks ,
2218) -> 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 ( ) ;
3422
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 ) ;
5034 }
51- let file = open_unchecked ( start, path, & opts) ?;
52- Metadata :: from_file ( & file)
5335 }
36+
37+ let file = open_unchecked ( start, path, & opts) ?;
38+ Metadata :: from_file ( & file)
5439}
0 commit comments