diff --git a/src/port/dirmod.c b/src/port/dirmod.c index 3db82e32ea9..08835962be6 100644 --- a/src/port/dirmod.c +++ b/src/port/dirmod.c @@ -372,7 +372,22 @@ pgwin32_safestat(const char *path, struct stat * buf) r = stat(path, buf); if (r < 0) + { + if (GetLastError() == ERROR_DELETE_PENDING) + { + /* + * File has been deleted, but is not gone from the filesystem + * yet. This can happen when some process with FILE_SHARE_DELETE + * has it open and it will be fully removed once that handle + * is closed. Meanwhile, we can't open it, so indicate that + * the file just doesn't exist. + */ + errno = ENOENT; + return -1; + } + return r; + } if (!GetFileAttributesEx(path, GetFileExInfoStandard, &attr)) { diff --git a/src/port/win32error.c b/src/port/win32error.c index 91095ee19a7..40655962a87 100644 --- a/src/port/win32error.c +++ b/src/port/win32error.c @@ -161,6 +161,9 @@ static const struct }, { ERROR_NOT_ENOUGH_QUOTA, ENOMEM + }, + { + ERROR_DELETE_PENDING, ENOENT } };