BUG #15822: Incorrect handling of pending deletes - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #15822: Incorrect handling of pending deletes
Date
Msg-id 15822-48a04833395f772c@postgresql.org
Whole thread Raw
List pgsql-bugs
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;
}


pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: BUG #15789: libpq compilation with OpenSSL 1.1.1b fails onWindows with Visual Studio 2017
Next
From: Nick Anderson
Date:
Subject: RE: Re: Re: RE: Re: Re: BUG #15769: The database cluster intialisation failed.