From 7d4d544001823db10493cc9c20efea91fcad55ad Mon Sep 17 00:00:00 2001 From: "William D. Jones" Date: Thu, 15 May 2025 18:36:04 -0400 Subject: [PATCH] Strip trailing slashes when checking for directories on Windows. --- kernel/io.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/io.cc b/kernel/io.cc index d5d2994b2..d7d126c4c 100644 --- a/kernel/io.cc +++ b/kernel/io.cc @@ -251,7 +251,15 @@ bool check_is_directory(const std::string& dirname) { #if defined(_WIN32) struct _stat info; - if (_stat(dirname.c_str(), &info) != 0) + auto dirname_ = dirname; + + /* On old versions of Visual Studio and current versions on MinGW, + _stat will fail if the path ends with a trailing slash. */ + if (dirname.back() == '/' || dirname.back() == '\\') { + dirname_ = dirname.substr(0, dirname.length() - 1); + } + + if (_stat(dirname_.c_str(), &info) != 0) { return false; }