Re: readdir is incorrectly implemented at Windows - Mailing list pgsql-hackers

From Grigory Smolkin
Subject Re: readdir is incorrectly implemented at Windows
Date
Msg-id [email protected]
Whole thread Raw
In response to readdir is incorrectly implemented at Windows  (Konstantin Knizhnik <[email protected]>)
List pgsql-hackers
Originally bug was reported by Yuri Kurenkov:
https://github.com/postgrespro/pg_probackup/issues/48

As pg_probackup rely on readdir() for listing files to backup, wrong 
permissions could lead to a broken backup.

On 02/25/2019 06:38 PM, Konstantin Knizhnik wrote:
> 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.
>

-- 
Grigory Smolkin
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company



pgsql-hackers by date:

Previous
From: Prabhat Sahu
Date:
Subject: pg_dump/pg_restore fail for TAR_DUMP and CUSTOM_DUMP from v94/v95/v96to v11/master.
Next
From: Joe Conway
Date:
Subject: Re: get_controlfile() can leak fds in the backend