From 482d9524b52a20fc0774f91e32c12828d2e723ff Mon Sep 17 00:00:00 2001 From: Jake Bailey Date: Wed, 12 Apr 2023 14:28:43 -0700 Subject: [PATCH] Treat mount point as symlink-like in finddata2dirent Testing on a pnpm monorepo containing recursive symlinks, it turns out that dwReserved0 is actually IO_REPARSE_TAG_MOUNT_POINT. Checking FILE_ATTRIBUTE_REPARSE_POINT and IO_REPARSE_TAG_MOUNT_POINT appears to match similar code in mingw.c's mingw_is_mount_point. The new test fails without this change, but I am unsure whether or not it needs some sort of conditional that checks that symlinks are available in Windows. "SYMLINK" used in the test file appears to be false even though I have developer mode enabled, allowing them. Signed-off-by: Jake Bailey --- compat/win32/dirent.c | 2 +- t/t7300-clean.sh | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/compat/win32/dirent.c b/compat/win32/dirent.c index 87063101f57202..01442f539f76c4 100644 --- a/compat/win32/dirent.c +++ b/compat/win32/dirent.c @@ -19,7 +19,7 @@ static inline void finddata2dirent(struct dirent *ent, WIN32_FIND_DATAW *fdata) /* Set file type, based on WIN32_FIND_DATA */ if ((fdata->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) - && fdata->dwReserved0 == IO_REPARSE_TAG_SYMLINK) + && (fdata->dwReserved0 == IO_REPARSE_TAG_SYMLINK || fdata->dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT)) ent->d_type = DT_LNK; else if (fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ent->d_type = DT_DIR; diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 121048e201064d..1d2b4e64419319 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -799,4 +799,26 @@ test_expect_success MINGW 'clean does not traverse mount points' ' test_path_is_file target/dont-clean-me ' +test_expect_success MINGW 'clean handles recursive symlink' ' + rm -fr repo && + mkdir repo && + ( + cd repo && + git init && + mkdir -p packages/some-package/node_modules && + cd packages/some-package && + touch package.json && + git add package.json && + git commit -m setup && + cd node_modules && + cmd //c "mklink /D /J some-package .." && + cd ../../.. && + test_path_is_file packages/some-package/package.json && + git clean -fdx packages 2>err && + test_path_is_file packages/some-package/package.json && + test_path_is_missing packages/some-package/node_modules && + ! test_i18ngrep "warning" err + ) +' + test_done