The following bug has been logged on the website:
Bug reference: 15822
Logged by: Konstantin Knizhnik
Email address: knizhnik@garret.ru
PostgreSQL version: 11.3
Operating system: Windows
Description:
Function pgwin32_safestat oncorrectly handles access to the fiel which
delete is pending because it is opened by some backends:
This functions assumes that stat() will return error in this case and
GetLastError - ERROR_DELETE_PENDING.
But actually ERROR_DELETE_PENDING is internal error code which is never
returned by Win32:
https://stackoverflow.com/questions/6680491/why-does-windows-return-error-access-denied-when-i-try-to-open-a-delete-pended-f
I have tested that stat() returns 0 (success) for such file and subsequent
call ofGetFileAttributesEx is failed with ERROR_ACCESS_DENIED error.
I think that this function should be rewritten to:
int
pgwin32_safestat(const char *path, struct stat *buf)
{
int r;
WIN32_FILE_ATTRIBUTE_DATA attr;
r = stat(path, buf);
if (r < 0)
return r;
if (!GetFileAttributesEx(path, GetFileExInfoStandard, &attr))
{
errno = ENOENT;
return -1;
}
/*
* XXX no support for large files here, but we don't do that in general
on
* Win32 yet.
*/
buf->st_size = attr.nFileSizeLow;
return 0;
}