MCPcopy Create free account
hub / github.com/Kitware/CMake / FileModificationTime

Method FileModificationTime

Source/cmTimestamp.cxx:70–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70std::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
97std::string cmTimestamp::CreateTimestampFromTimeT(time_t timeT,
98 std::string formatString,

Callers 1

HandleTimestampCommandFunction · 0.80

Calls 5

c_strMethod · 0.80
FileExistsFunction · 0.50
uv_fs_statFunction · 0.50
uv_fs_req_cleanupFunction · 0.50

Tested by

no test coverage detected