From cbbf552c691ad83862c1fcb9608dae5211ef61cb Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Tue, 10 Nov 2026 23:09:20 +0000 Subject: [PATCH] fs.readdirSync on a file: ENOTDIR on Windows, not EINVAL Windows gives ERROR_DIRECTORY for a directory iterator opened on a file, which MSVC maps to EINVAL; Node says ENOTDIR. tslang_fs_read_dir now checks for an existing non-directory when the listing fails and reports ENOTDIR. fs.ts's "list a file" failed on every Windows job. Co-Authored-By: Claude Opus 5.5 --- src/wrappers/os.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wrappers/os.cpp b/src/wrappers/os.cpp index 91a99fc..fd70caa 100644 --- a/src/wrappers/os.cpp +++ b/src/wrappers/os.cpp @@ -632,6 +632,14 @@ extern "C" TSLANG_EXPORT int tslang_fs_read_dir(const char *path) fs::directory_iterator it(to_path(path), ec); if (ec) { + // Windows says ERROR_DIRECTORY for a file, which MSVC maps to EINVAL; Node says ENOTDIR + std::error_code statError; + auto status = fs::status(to_path(path), statError); + if (!statError && fs::exists(status) && !fs::is_directory(status)) + { + return fail_errc(std::errc::not_a_directory, "scandir", path); + } + return fail(ec, "scandir", path); }