This commit is contained in:
yhirose 2024-09-02 20:38:01 -04:00
parent 4f9c6540b2
commit 2514ebc20f
2 changed files with 11 additions and 4 deletions

View File

@ -2526,12 +2526,8 @@ inline std::string base64_encode(const std::string &in) {
} }
inline bool is_file(const std::string &path) { inline bool is_file(const std::string &path) {
#ifdef _WIN32
return _access_s(path.c_str(), 0) == 0;
#else
struct stat st; struct stat st;
return stat(path.c_str(), &st) >= 0 && S_ISREG(st.st_mode); return stat(path.c_str(), &st) >= 0 && S_ISREG(st.st_mode);
#endif
} }
inline bool is_dir(const std::string &path) { inline bool is_dir(const std::string &path) {

View File

@ -7561,3 +7561,14 @@ TEST(UniversalClientImplTest, Ipv6LiteralAddress) {
CLIENT_PRIVATE_KEY_FILE); CLIENT_PRIVATE_KEY_FILE);
EXPECT_EQ(cli.port(), port); EXPECT_EQ(cli.port(), port);
} }
TEST(FileSystemTest, FileAndDirExistenceCheck) {
auto file_path = "./www/dir/index.html";
auto dir_path = "./www/dir";
EXPECT_TRUE(detail::is_file(file_path));
EXPECT_FALSE(detail::is_dir(file_path));
EXPECT_FALSE(detail::is_file(dir_path));
EXPECT_TRUE(detail::is_dir(dir_path));
}