Re: pg_tablespace_location() failure with allow_in_place_tablespaces

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-03-26T05:33:46Z
Lists: pgsql-hackers
On Thu, Mar 24, 2022 at 04:41:30PM +1300, Thomas Munro wrote:
> As mentioned, I was unhappy with the lack of error checking for that
> interface, and I've started a new thread about that, but then I
> started wondering if we missed a trick here: get_dirent_type() contain
> code that wants to return PGFILETYPE_LNK for reparse points.  Clearly
> it's not working, based on results reported in this thread.  Is that
> explained by your comment above, "junction points _are_ directories",
> and we're testing the attribute flags in the wrong order here?
> 
>     if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
>         d->ret.d_type = DT_DIR;
>     /* For reparse points dwReserved0 field will contain the ReparseTag */
>     else if ((fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0 &&
>              (fd.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT))
>         d->ret.d_type = DT_LNK;
>     else
>         d->ret.d_type = DT_REG;

Ah, good point.  I have not tested on Windows so I am not 100% sure,
but indeed it would make sense to reverse both conditions if a
junction point happens to be marked as both FILE_ATTRIBUTE_DIRECTORY
and FILE_ATTRIBUTE_REPARSE_POINT when scanning a directory.  Based on
a read of the the upstream docs, I guess that this is the case:
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/ca28ec38-f155-4768-81d6-4bfeb8586fc9

Note the "A file or directory that has an associated reparse point."
for the description of FILE_ATTRIBUTE_REPARSE_POINT.
--
Michael

Commits

  1. Remove unnecessary Windows-specific basebackup code.

  2. Fix get_dirent_type() for Windows junction points.

  3. doc: Remove mention to in-place tablespaces for pg_tablespace_location()

  4. Fix pg_tablespace_location() with in-place tablespaces

  5. Fix pg_basebackup with in-place tablespaces.