summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorItai Steinherz <itaisteinherz@gmail.com>2022-05-02 23:19:13 (GMT)
committerGitHub <noreply@github.com>2022-05-02 23:19:13 (GMT)
commit39e6b8ae6a5b49bb23746fdcc354d148ff2d98e3 (patch)
tree0744e51c145b37baa6335749d890bd1efba5f19f /Modules/posixmodule.c
parentebb8b512e959ca1a0a506ac0f0faf461b1b2ff85 (diff)
downloadcpython-39e6b8ae6a5b49bb23746fdcc354d148ff2d98e3.zip
cpython-39e6b8ae6a5b49bb23746fdcc354d148ff2d98e3.tar.gz
cpython-39e6b8ae6a5b49bb23746fdcc354d148ff2d98e3.tar.bz2
bpo-46785: Fix race condition between os.stat() and unlink on Windows (GH-31858)
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 a2ea507..a7f5780 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1890,7 +1890,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) {