From 13994fb3e4534fec40356da00d5efad432c9b269 Mon Sep 17 00:00:00 2001 From: Chris Miles Date: Sun, 11 Feb 2024 02:42:25 -0600 Subject: [PATCH] [File] Fix File::Exists(file_name) to be resilient to Chinese characters (#4058) * Update file.cpp * Update file.cpp * Update file.cpp * Update file.cpp * Update file.cpp * Update file.cpp * Update file.cpp * Update file.cpp * Final fix --- common/file.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/file.cpp b/common/file.cpp index 632d1696b..effed63b0 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -38,21 +38,21 @@ #include #include #include +#include namespace fs = std::filesystem; -/** - * @param name - * @return - */ + bool File::Exists(const std::string &name) { - return fs::exists(fs::path{name}); + struct stat sb{}; + if (stat(name.c_str(), &sb) == 0) { + return true; + } + + return false; } -/** - * @param directory_name - */ void File::Makedir(const std::string &directory_name) { try {