int64_t GetFileSize(const std::string &filepath) { const char* path_str = filepath.c_str(); stat_wrapper_t file_info; int test = CallStat(path_str, &file_info); if (test != 0) return -1; if (!S_ISDIR(file_info.st_mode)) return file_info.st_size; return -1; }
// static bool PathService::DirectoryExists(const std::string& path) { #ifdef _WIN32 DWORD fileattr = GetFileAttributesA(path.c_str()); if (fileattr != INVALID_FILE_ATTRIBUTES) return (fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0; return false; #else stat_wrapper_t file_info; if (CallStat(path.c_str(), &file_info) != 0) return false; return S_ISDIR(file_info.st_mode); #endif }
bool DeleteFile(const std::string &filepath) { const char* path_str = filepath.c_str(); stat_wrapper_t file_info; int test = CallStat(path_str, &file_info); if (test != 0) { // The Windows version defines this condition as success. bool ret = (errno == ENOENT || errno == ENOTDIR); return ret; } if (!S_ISDIR(file_info.st_mode)) return (unlink(path_str) == 0); return true; }