summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorItai Steinherz <itaisteinherz@gmail.com>2022-05-09 22:42:59 (GMT)
committerGitHub <noreply@github.com>2022-05-09 22:42:59 (GMT)
commit1fb25a96aeceae4b8615a7ab550bf7538353e5c5 (patch)
treec36ba26e13b22889341766ba904656e99042bad2 /Modules/posixmodule.c
parent249be828e475202fd6f63fc357be75eca1267c9f (diff)
downloadcpython-1fb25a96aeceae4b8615a7ab550bf7538353e5c5.zip
cpython-1fb25a96aeceae4b8615a7ab550bf7538353e5c5.tar.gz
cpython-1fb25a96aeceae4b8615a7ab550bf7538353e5c5.tar.bz2
bpo-46785: Fix race condition between os.stat() and unlink on Windows (GH-31858)
* [3.9] bpo-46785: Fix race condition between os.stat() and unlink on Windows (GH-31858). (cherry picked from commit 39e6b8ae6a5b49bb23746fdcc354d148ff2d98e3) Co-authored-by: Itai Steinherz <itaisteinherz@gmail.com>
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 29d6126..1270af7 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1853,7 +1853,17 @@ win32_xstat_impl(const wchar_t *path, struct _Py_stat_struct *result,
/* Try reading the parent directory. */
if (!attributes_from_dir(path, &fileInfo, &tagInfo.ReparseTag)) {
/* Cannot read the parent directory. */
- SetLastError(error);
+ switch (GetLastError()) {
+ case ERROR_FILE_NOT_FOUND: /* File cannot be found */
+ case ERROR_PATH_NOT_FOUND: /* File parent directory cannot be found */
+ case ERROR_NOT_READY: /* Drive exists but unavailable */
+ case ERROR_BAD_NET_NAME: /* Remote drive unavailable */
+ break;
+ /* Restore the error from CreateFileW(). */
+ default:
+ SetLastError(error);
+ }
+
return -1;
}
if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {