From fcc325ffbb47362cdfbb5dd2057cffe9c06030fb Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Tue, 3 Sep 2024 15:57:12 +0200 Subject: [PATCH] ensure detection of entry type on windows is reliable it seems that there is a possibility for the type detection to report a folder as being a file with this change, I am pretty sure that cannot happen any longer Signed-off-by: Matthieu Gallien --- src/csync/vio/csync_vio_local_win.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/csync/vio/csync_vio_local_win.cpp b/src/csync/vio/csync_vio_local_win.cpp index d0dec638a4791..76aa4a45a3a18 100644 --- a/src/csync/vio/csync_vio_local_win.cpp +++ b/src/csync/vio/csync_vio_local_win.cpp @@ -142,9 +142,11 @@ std::unique_ptr csync_vio_local_readdir(csync_vio_handle_t *h file_stat = std::make_unique(); file_stat->path = path.toUtf8(); + const auto isDirectory = handle->ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; + if (vfs && vfs->statTypeVirtualFile(file_stat.get(), &handle->ffd)) { // all good - } else if (handle->ffd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) { + } else if ((handle->ffd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) && !isDirectory) { // Detect symlinks, and treat junctions as symlinks too. if (handle->ffd.dwReserved0 == IO_REPARSE_TAG_SYMLINK || handle->ffd.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT) { @@ -155,11 +157,10 @@ std::unique_ptr csync_vio_local_readdir(csync_vio_handle_t *h // but will also treat them normally for now. file_stat->type = ItemTypeFile; } - } else if (handle->ffd.dwFileAttributes & FILE_ATTRIBUTE_DEVICE - || handle->ffd.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE - ) { + } else if ((handle->ffd.dwFileAttributes & FILE_ATTRIBUTE_DEVICE || handle->ffd.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE) && + !isDirectory) { file_stat->type = ItemTypeSkip; - } else if (handle->ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + } else if (isDirectory) { file_stat->type = ItemTypeDirectory; } else { file_stat->type = ItemTypeFile;