Skip to content

Commit 7c0a90c

Browse files
committedNov 8, 2024
Address review comments
1 parent ac66068 commit 7c0a90c

File tree

1 file changed

+24
-32
lines changed
  • std/src/sys/pal/windows

1 file changed

+24
-32
lines changed
 

‎std/src/sys/pal/windows/fs.rs

+24-32
Original file line numberDiff line numberDiff line change
@@ -367,26 +367,16 @@ impl File {
367367
Ok(_) => Ok(()),
368368
Err(err) => {
369369
if err.raw_os_error() == Some(c::ERROR_IO_PENDING as i32) {
370-
// Wait for the lock to be acquired. This can happen asynchronously,
371-
// if the file handle was opened for async IO
372-
let wait_result = c::WaitForSingleObject(overlapped.hEvent, c::INFINITE);
373-
if wait_result == c::WAIT_OBJECT_0 {
374-
// Wait completed successfully, get the lock operation status
375-
let mut bytes_transferred = 0;
376-
cvt(c::GetOverlappedResult(
377-
self.handle.as_raw_handle(),
378-
&mut overlapped,
379-
&mut bytes_transferred,
380-
c::TRUE,
381-
))
382-
.map(|_| ())
383-
} else if wait_result == c::WAIT_FAILED {
384-
// Wait failed
385-
Err(io::Error::last_os_error())
386-
} else {
387-
// WAIT_ABANDONED and WAIT_TIMEOUT should not be possible
388-
unreachable!()
389-
}
370+
// Wait for the lock to be acquired, and get the lock operation status.
371+
// This can happen asynchronously, if the file handle was opened for async IO
372+
let mut bytes_transferred = 0;
373+
cvt(c::GetOverlappedResult(
374+
self.handle.as_raw_handle(),
375+
&mut overlapped,
376+
&mut bytes_transferred,
377+
c::TRUE,
378+
))
379+
.map(|_| ())
390380
} else {
391381
Err(err)
392382
}
@@ -418,15 +408,16 @@ impl File {
418408
)
419409
});
420410

421-
if let Err(ref err) = result {
422-
if err.raw_os_error() == Some(c::ERROR_IO_PENDING as i32)
423-
|| err.raw_os_error() == Some(c::ERROR_LOCK_VIOLATION as i32)
411+
match result {
412+
Ok(_) => Ok(true),
413+
Err(err)
414+
if err.raw_os_error() == Some(c::ERROR_IO_PENDING as i32)
415+
|| err.raw_os_error() == Some(c::ERROR_LOCK_VIOLATION as i32) =>
424416
{
425-
return Ok(false);
417+
Ok(false)
426418
}
419+
Err(err) => Err(err),
427420
}
428-
result?;
429-
Ok(true)
430421
}
431422

432423
pub fn try_lock_shared(&self) -> io::Result<bool> {
@@ -442,15 +433,16 @@ impl File {
442433
)
443434
});
444435

445-
if let Err(ref err) = result {
446-
if err.raw_os_error() == Some(c::ERROR_IO_PENDING as i32)
447-
|| err.raw_os_error() == Some(c::ERROR_LOCK_VIOLATION as i32)
436+
match result {
437+
Ok(_) => Ok(true),
438+
Err(err)
439+
if err.raw_os_error() == Some(c::ERROR_IO_PENDING as i32)
440+
|| err.raw_os_error() == Some(c::ERROR_LOCK_VIOLATION as i32) =>
448441
{
449-
return Ok(false);
442+
Ok(false)
450443
}
444+
Err(err) => Err(err),
451445
}
452-
result?;
453-
Ok(true)
454446
}
455447

456448
pub fn unlock(&self) -> io::Result<()> {

0 commit comments

Comments
 (0)
Please sign in to comment.