Win: Open dir for sync access in remove_dir_all · qinheping/verify-rust-std@be2b964 (original) (raw)
`@@ -71,10 +71,12 @@ unsafe fn nt_open_file(
`
71
71
`}
`
72
72
``
73
73
`` /// Open the file path
in the directory parent
, requesting the given access
rights.
``
``
74
`` +
/// options
will be OR'd with FILE_OPEN_REPARSE_POINT
.
``
74
75
`fn open_link_no_reparse(
`
75
76
`parent: &File,
`
76
77
`path: &[u16],
`
77
78
`access: u32,
`
``
79
`+
options: u32,
`
78
80
`) -> Result<Option, WinError> {
`
79
81
`` // This is implemented using the lower level NtOpenFile
function as
``
80
82
`// unfortunately opening a file relative to a parent is not supported by
`
`@@ -96,7 +98,7 @@ fn open_link_no_reparse(
`
96
98
` ..c::OBJECT_ATTRIBUTES::default()
`
97
99
`};
`
98
100
`let share = c::FILE_SHARE_DELETE | c::FILE_SHARE_READ | c::FILE_SHARE_WRITE;
`
99
``
`-
let options = c::FILE_OPEN_REPARSE_POINT;
`
``
101
`+
let options = c::FILE_OPEN_REPARSE_POINT | options;
`
100
102
`let result = nt_open_file(access, &object, share, options);
`
101
103
``
102
104
`// Retry without OBJ_DONT_REPARSE if it's not supported.
`
`@@ -128,13 +130,20 @@ fn open_link_no_reparse(
`
128
130
`}
`
129
131
``
130
132
`fn open_dir(parent: &File, name: &[u16]) -> Result<Option, WinError> {
`
131
``
`-
open_link_no_reparse(parent, name, c::SYNCHRONIZE | c::FILE_LIST_DIRECTORY)
`
``
133
`+
// Open the directory for synchronous directory listing.
`
``
134
`+
open_link_no_reparse(
`
``
135
`+
parent,
`
``
136
`+
name,
`
``
137
`+
c::SYNCHRONIZE | c::FILE_LIST_DIRECTORY,
`
``
138
`+
// "_IO_NONALERT" means that a synchronous call won't be interrupted.
`
``
139
`+
c::FILE_SYNCHRONOUS_IO_NONALERT,
`
``
140
`+
)
`
132
141
`}
`
133
142
``
134
143
`fn delete(parent: &File, name: &[u16]) -> Result<(), WinError> {
`
135
144
`` // Note that the delete
function consumes the opened file to ensure it's
``
136
145
`// dropped immediately. See module comments for why this is important.
`
137
``
`-
match open_link_no_reparse(parent, name, c::SYNCHRONIZE | c::DELETE) {
`
``
146
`+
match open_link_no_reparse(parent, name, c::DELETE, 0) {
`
138
147
`Ok(Some(f)) => f.delete(),
`
139
148
`Ok(None) => Ok(()),
`
140
149
`Err(e) => Err(e),
`