| 82 | } |
| 83 | |
| 84 | bool GetFileCacheKey(const std::string& path, std::string* cacheKey) { |
| 85 | #if defined(_WIN32) || defined(_WIN64) |
| 86 | WIN32_FILE_ATTRIBUTE_DATA fileInfo; |
| 87 | const std::wstring widePath = internal::WideFromUtf8(path); |
| 88 | if (widePath.empty() || |
| 89 | !GetFileAttributesExW(widePath.c_str(), GetFileExInfoStandard, |
| 90 | &fileInfo)) { |
| 91 | return false; |
| 92 | } |
| 93 | #else |
| 94 | struct stat statBuf; |
| 95 | if (stat(path.c_str(), &statBuf) != 0) { |
| 96 | return false; |
| 97 | } |
| 98 | #endif |
| 99 | *cacheKey = path; |
| 100 | cacheKey->push_back('\n'); |
| 101 | #if defined(_WIN32) || defined(_WIN64) |
| 102 | cacheKey->append( |
| 103 | std::to_string(static_cast<unsigned long long>( |
| 104 | fileInfo.ftLastWriteTime.dwHighDateTime))); |
| 105 | cacheKey->push_back('.'); |
| 106 | cacheKey->append( |
| 107 | std::to_string(static_cast<unsigned long long>( |
| 108 | fileInfo.ftLastWriteTime.dwLowDateTime))); |
| 109 | cacheKey->push_back('\n'); |
| 110 | cacheKey->append( |
| 111 | std::to_string(static_cast<unsigned long long>(fileInfo.nFileSizeHigh))); |
| 112 | cacheKey->push_back('.'); |
| 113 | cacheKey->append( |
| 114 | std::to_string(static_cast<unsigned long long>(fileInfo.nFileSizeLow))); |
| 115 | #else |
| 116 | cacheKey->append(std::to_string(static_cast<long long>(statBuf.st_mtime))); |
| 117 | cacheKey->push_back('.'); |
| 118 | #if defined(__APPLE__) && defined(__MACH__) |
| 119 | cacheKey->append( |
| 120 | std::to_string(static_cast<long long>(statBuf.st_mtimespec.tv_nsec))); |
| 121 | #elif defined(st_mtime_nsec) |
| 122 | cacheKey->append( |
| 123 | std::to_string(static_cast<long long>(statBuf.st_mtime_nsec))); |
| 124 | #else |
| 125 | cacheKey->append( |
| 126 | std::to_string(static_cast<long long>(statBuf.st_mtim.tv_nsec))); |
| 127 | #endif |
| 128 | cacheKey->push_back('\n'); |
| 129 | cacheKey->append(std::to_string(static_cast<long long>(statBuf.st_size))); |
| 130 | #endif |
| 131 | return true; |
| 132 | } |
| 133 | |
| 134 | FILE* OpenFileUtf8(const std::string& path, const char* mode) { |
| 135 | #if defined(_WIN32) || defined(_WIN64) |
no test coverage detected