readdir is incorrectly implemented at Windows
Konstantin Knizhnik <k.knizhnik@postgrespro.ru>
From: Konstantin Knizhnik <k.knizhnik@postgrespro.ru>
To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2019-02-25T15:38:16Z
Lists: pgsql-hackers
Attachments
- dirent.patch (text/x-patch) patch
Hi hackers,
Small issue with readir implementation for Windows.
Right now it returns ENOENT in case of any error returned by FindFirstFile.
So all places in Postgres where opendir/listdir are used will assume
that directory is empty and
do nothing without reporting any error.
It is not so good if directory is actually not empty but there are not
enough permissions for accessing the directory and FindFirstFile
returns ERROR_ACCESS_DENIED:
struct dirent *
readdir(DIR *d)
{
WIN32_FIND_DATA fd;
if (d->handle == INVALID_HANDLE_VALUE)
{
d->handle = FindFirstFile(d->dirname, &fd);
if (d->handle == INVALID_HANDLE_VALUE)
{
errno = ENOENT;
return NULL;
}
}
Attached please find small patch fixing the problem.
--
Konstantin Knizhnik
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Commits
-
Fix error handling of readdir() port implementation on first file lookup
- 81f5b32839ff 9.4.22 landed
- 977f833772de 9.5.17 landed
- d95133163b1b 9.6.13 landed
- 9aa59e64ba75 10.8 landed
- 8722c4daccf8 11.3 landed
- 754b90f657bd 12.0 landed