Skip to content

Commit

Permalink
ensure detection of entry type on windows is reliable
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mgallien authored and backportbot[bot] committed Sep 9, 2024
1 parent dbfc82c commit 7d4c5a4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/csync/vio/csync_vio_local_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ std::unique_ptr<csync_file_stat_t> csync_vio_local_readdir(csync_vio_handle_t *h
file_stat = std::make_unique<csync_file_stat_t>();
file_stat->path = path.toUtf8();

const auto isDirectory = handle->ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;

if (vfs && vfs->statTypeVirtualFile(file_stat.get(), &handle->ffd)) {

Check warning on line 147 in src/csync/vio/csync_vio_local_win.cpp

View workflow job for this annotation

GitHub Actions / build

src/csync/vio/csync_vio_local_win.cpp:147:73 [bugprone-branch-clone]

repeated branch in conditional chain
// 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) {
Expand All @@ -155,11 +157,10 @@ std::unique_ptr<csync_file_stat_t> 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;
Expand Down

0 comments on commit 7d4c5a4

Please sign in to comment.