Skip to content

Commit 7d4d544

Browse files
committed
Strip trailing slashes when checking for directories on Windows.
1 parent 4c72b0e commit 7d4d544

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

kernel/io.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,15 @@ bool check_is_directory(const std::string& dirname)
251251
{
252252
#if defined(_WIN32)
253253
struct _stat info;
254-
if (_stat(dirname.c_str(), &info) != 0)
254+
auto dirname_ = dirname;
255+
256+
/* On old versions of Visual Studio and current versions on MinGW,
257+
_stat will fail if the path ends with a trailing slash. */
258+
if (dirname.back() == '/' || dirname.back() == '\\') {
259+
dirname_ = dirname.substr(0, dirname.length() - 1);
260+
}
261+
262+
if (_stat(dirname_.c_str(), &info) != 0)
255263
{
256264
return false;
257265
}

0 commit comments

Comments
 (0)