From 6d31b157a009030272a9981354d89036de1d7e79 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Sun, 1 Nov 2026 22:55:27 +0300 Subject: [PATCH] Ask FindFirstFileW for the reparse tag only when the path is a reparse point plat_fs_kind served every path through FindFirstFileW, which fails on a path with a trailing separator and reads wildcards. GetFileAttributesW decides again, as before; only reparse points need the find data's tag. Co-Authored-By: Claude Opus 5.5 --- runtime/platform/win32.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/runtime/platform/win32.c b/runtime/platform/win32.c index 3934f87f..1d70c18d 100644 --- a/runtime/platform/win32.c +++ b/runtime/platform/win32.c @@ -892,9 +892,14 @@ static int fs_kind_of(const WIN32_FIND_DATAW *fd) { int plat_fs_kind(const char *path) { wchar_t w[WPATH]; if (!widen(path, w, WPATH)) return PLAT_FS_MISSING; + DWORD a = GetFileAttributesW(w); + if (a == INVALID_FILE_ATTRIBUTES) return PLAT_FS_MISSING; + if (!(a & FILE_ATTRIBUTE_REPARSE_POINT)) return a & FILE_ATTRIBUTE_DIRECTORY ? PLAT_FS_DIR : PLAT_FS_FILE; + // the reparse tag comes with the find data only; FindFirstFileW is asked only here, since it fails on a path + // with a trailing separator and reads wildcards WIN32_FIND_DATAW fd; - HANDLE h = FindFirstFileW(w, &fd); // the reparse tag comes with the find data only - if (h == INVALID_HANDLE_VALUE) return PLAT_FS_MISSING; + HANDLE h = FindFirstFileW(w, &fd); + if (h == INVALID_HANDLE_VALUE) return PLAT_FS_LINK; FindClose(h); return fs_kind_of(&fd); }