| 131 | } |
| 132 | |
| 133 | bool GetFileFreshnessCacheKey(const std::string& path, std::string* cacheKey) { |
| 134 | #if defined(_WIN32) || defined(_WIN64) |
| 135 | WIN32_FILE_ATTRIBUTE_DATA fileInfo; |
| 136 | const std::wstring widePath = internal::WideFromUtf8(path); |
| 137 | if (widePath.empty() || |
| 138 | !GetFileAttributesExW(widePath.c_str(), GetFileExInfoStandard, |
| 139 | &fileInfo)) { |
| 140 | return false; |
| 141 | } |
| 142 | #else |
| 143 | struct stat statBuf; |
| 144 | if (stat(path.c_str(), &statBuf) != 0) { |
| 145 | return false; |
| 146 | } |
| 147 | #endif |
| 148 | *cacheKey = path; |
| 149 | cacheKey->push_back('\n'); |
| 150 | #if defined(_WIN32) || defined(_WIN64) |
| 151 | cacheKey->append( |
| 152 | std::to_string(static_cast<unsigned long long>( |
| 153 | fileInfo.ftLastWriteTime.dwHighDateTime))); |
| 154 | cacheKey->push_back('.'); |
| 155 | cacheKey->append( |
| 156 | std::to_string(static_cast<unsigned long long>( |
| 157 | fileInfo.ftLastWriteTime.dwLowDateTime))); |
| 158 | cacheKey->push_back('\n'); |
| 159 | cacheKey->append( |
| 160 | std::to_string(static_cast<unsigned long long>(fileInfo.nFileSizeHigh))); |
| 161 | cacheKey->push_back('.'); |
| 162 | cacheKey->append( |
| 163 | std::to_string(static_cast<unsigned long long>(fileInfo.nFileSizeLow))); |
| 164 | #else |
| 165 | cacheKey->append(std::to_string(static_cast<long long>(statBuf.st_mtime))); |
| 166 | cacheKey->push_back('.'); |
| 167 | #if defined(__APPLE__) && defined(__MACH__) |
| 168 | cacheKey->append( |
| 169 | std::to_string(static_cast<long long>(statBuf.st_mtimespec.tv_nsec))); |
| 170 | #elif defined(st_mtime_nsec) |
| 171 | cacheKey->append( |
| 172 | std::to_string(static_cast<long long>(statBuf.st_mtime_nsec))); |
| 173 | #else |
| 174 | cacheKey->append( |
| 175 | std::to_string(static_cast<long long>(statBuf.st_mtim.tv_nsec))); |
| 176 | #endif |
| 177 | cacheKey->push_back('\n'); |
| 178 | cacheKey->append(std::to_string(static_cast<long long>(statBuf.st_size))); |
| 179 | #endif |
| 180 | return true; |
| 181 | } |
| 182 | |
| 183 | #if defined(_WIN32) || defined(_WIN64) |
| 184 | std::vector<unsigned char> ReadBinaryFile(const std::string& path) { |
no test coverage detected