about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristopher Berner <me@cberner.com>2024-11-08 08:16:41 -0800
committerChristopher Berner <me@cberner.com>2024-11-08 08:16:41 -0800
commit9330786c278c0dd733a6ef7dae23b8ee14db39d1 (patch)
tree9d1b9d0d3bf591d5e31225b0ebfa604e2941cfd0
parent5a156a79994bf4722a50adad637bd7d0d747abe3 (diff)
downloadrust-9330786c278c0dd733a6ef7dae23b8ee14db39d1.tar.gz
rust-9330786c278c0dd733a6ef7dae23b8ee14db39d1.zip
Address review comments
-rw-r--r--library/std/src/sys/pal/windows/fs.rs56
1 files changed, 24 insertions, 32 deletions
diff --git a/library/std/src/sys/pal/windows/fs.rs b/library/std/src/sys/pal/windows/fs.rs
index 7bb0e84c88f..307200e49c7 100644
--- a/library/std/src/sys/pal/windows/fs.rs
+++ b/library/std/src/sys/pal/windows/fs.rs
@@ -367,26 +367,16 @@ impl File {
                 Ok(_) => Ok(()),
                 Err(err) => {
                     if err.raw_os_error() == Some(c::ERROR_IO_PENDING as i32) {
-                        // Wait for the lock to be acquired. This can happen asynchronously,
-                        // if the file handle was opened for async IO
-                        let wait_result = c::WaitForSingleObject(overlapped.hEvent, c::INFINITE);
-                        if wait_result == c::WAIT_OBJECT_0 {
-                            // Wait completed successfully, get the lock operation status
-                            let mut bytes_transferred = 0;
-                            cvt(c::GetOverlappedResult(
-                                self.handle.as_raw_handle(),
-                                &mut overlapped,
-                                &mut bytes_transferred,
-                                c::TRUE,
-                            ))
-                            .map(|_| ())
-                        } else if wait_result == c::WAIT_FAILED {
-                            // Wait failed
-                            Err(io::Error::last_os_error())
-                        } else {
-                            // WAIT_ABANDONED and WAIT_TIMEOUT should not be possible
-                            unreachable!()
-                        }
+                        // Wait for the lock to be acquired, and get the lock operation status.
+                        // This can happen asynchronously, if the file handle was opened for async IO
+                        let mut bytes_transferred = 0;
+                        cvt(c::GetOverlappedResult(
+                            self.handle.as_raw_handle(),
+                            &mut overlapped,
+                            &mut bytes_transferred,
+                            c::TRUE,
+                        ))
+                        .map(|_| ())
                     } else {
                         Err(err)
                     }
@@ -418,15 +408,16 @@ impl File {
             )
         });
 
-        if let Err(ref err) = result {
-            if err.raw_os_error() == Some(c::ERROR_IO_PENDING as i32)
-                || err.raw_os_error() == Some(c::ERROR_LOCK_VIOLATION as i32)
+        match result {
+            Ok(_) => Ok(true),
+            Err(err)
+                if err.raw_os_error() == Some(c::ERROR_IO_PENDING as i32)
+                    || err.raw_os_error() == Some(c::ERROR_LOCK_VIOLATION as i32) =>
             {
-                return Ok(false);
+                Ok(false)
             }
+            Err(err) => Err(err),
         }
-        result?;
-        Ok(true)
     }
 
     pub fn try_lock_shared(&self) -> io::Result<bool> {
@@ -442,15 +433,16 @@ impl File {
             )
         });
 
-        if let Err(ref err) = result {
-            if err.raw_os_error() == Some(c::ERROR_IO_PENDING as i32)
-                || err.raw_os_error() == Some(c::ERROR_LOCK_VIOLATION as i32)
+        match result {
+            Ok(_) => Ok(true),
+            Err(err)
+                if err.raw_os_error() == Some(c::ERROR_IO_PENDING as i32)
+                    || err.raw_os_error() == Some(c::ERROR_LOCK_VIOLATION as i32) =>
             {
-                return Ok(false);
+                Ok(false)
             }
+            Err(err) => Err(err),
         }
-        result?;
-        Ok(true)
     }
 
     pub fn unlock(&self) -> io::Result<()> {