| 68 | } |
| 69 | |
| 70 | std::string cmTimestamp::FileModificationTime(char const* path, |
| 71 | cm::string_view formatString, |
| 72 | bool utcFlag) const |
| 73 | { |
| 74 | std::string real_path = |
| 75 | cmSystemTools::GetRealPathResolvingWindowsSubst(path); |
| 76 | |
| 77 | if (!cmsys::SystemTools::FileExists(real_path)) { |
| 78 | return std::string(); |
| 79 | } |
| 80 | |
| 81 | // use libuv's implementation of stat(2) to get the file information |
| 82 | time_t mtime = 0; |
| 83 | uint32_t microseconds = 0; |
| 84 | uv_fs_t req; |
| 85 | if (uv_fs_stat(nullptr, &req, real_path.c_str(), nullptr) == 0) { |
| 86 | mtime = static_cast<time_t>(req.statbuf.st_mtim.tv_sec); |
| 87 | // tv_nsec has nanosecond resolution, but we truncate it to microsecond |
| 88 | // resolution in order to be consistent with cmTimestamp::CurrentTime() |
| 89 | microseconds = static_cast<uint32_t>(req.statbuf.st_mtim.tv_nsec / 1000); |
| 90 | } |
| 91 | uv_fs_req_cleanup(&req); |
| 92 | |
| 93 | return this->CreateTimestampFromTimeT( |
| 94 | mtime, microseconds, static_cast<std::string>(formatString), utcFlag); |
| 95 | } |
| 96 | |
| 97 | std::string cmTimestamp::CreateTimestampFromTimeT(time_t timeT, |
| 98 | std::string formatString, |
no test coverage detected