This is an automated email from the ASF dual-hosted git repository.

reshke pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit c06cf789ce7a7c9c2d288b72d8fb99c64c290418
Author: Thomas Munro <[email protected]>
AuthorDate: Fri Jul 22 16:57:12 2022 +1200

    Fix get_dirent_type() for Windows junction points.
    
    Commit 87e6ed7c8 added code that intended to report Windows "junction
    points" as DT_LNK (the same way we report symlinks on Unix).  Windows
    junction points are *also* directories according to the Windows
    attributes API, and we were reporting them as as DT_DIR.  Change the
    order we check the attribute flags, to prioritize DT_LNK.
    
    If at some point we start using Windows' recently added real symlinks
    and need to distinguish them from junction points, we may need to
    rethink this, but for now this continues the tradition of wrapper
    functions that treat junction points as symlinks.
    
    Back-patch to 14, where get_dirent_type() landed.
    
    Reviewed-by: Michael Paquier <[email protected]>
    Reviewed-by: Alvaro Herrera <[email protected]>
    Discussion: 
https://postgr.es/m/CA%2BhUKGLzLK4PUPx0_AwXEWXOYAejU%3D7XpxnYE55Y%2Be7hB2N3FA%40mail.gmail.com
    Discussion: 
https://postgr.es/m/20220721111751.x7hod2xgrd76xr5c%40alvherre.pgsql
---
 src/port/dirent.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/port/dirent.c b/src/port/dirent.c
index 77b90e7e302..2cd134495ff 100644
--- a/src/port/dirent.c
+++ b/src/port/dirent.c
@@ -106,13 +106,17 @@ readdir(DIR *d)
        }
        strcpy(d->ret.d_name, fd.cFileName);    /* Both strings are MAX_PATH 
long */
        d->ret.d_namlen = strlen(d->ret.d_name);
-       /* The only identified types are: directory, regular file or symbolic 
link */
-       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))
+
+       /*
+        * For reparse points dwReserved0 field will contain the ReparseTag.  We
+        * check this first, because reparse points are also reported as
+        * directories.
+        */
+       if ((fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0 &&
+               (fd.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT))
                d->ret.d_type = DT_LNK;
+       else if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
+               d->ret.d_type = DT_DIR;
        else
                d->ret.d_type = DT_REG;
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to