| 71 | cmFileTimes::~cmFileTimes() = default; |
| 72 | |
| 73 | cmsys::Status cmFileTimes::Load(std::string const& fileName) |
| 74 | { |
| 75 | std::unique_ptr<Times> ptr; |
| 76 | if (this->IsValid()) { |
| 77 | // Invalidate this and reuse times |
| 78 | ptr.swap(this->times); |
| 79 | } else { |
| 80 | ptr = cm::make_unique<Times>(); |
| 81 | } |
| 82 | |
| 83 | #if defined(_WIN32) && !defined(__CYGWIN__) |
| 84 | cmFileTimes::WindowsHandle handle = |
| 85 | CreateFileW(cmSystemTools::ConvertToWindowsExtendedPath(fileName).c_str(), |
| 86 | GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, |
| 87 | FILE_FLAG_BACKUP_SEMANTICS, 0); |
| 88 | if (!handle) { |
| 89 | return cmsys::Status::Windows_GetLastError(); |
| 90 | } |
| 91 | if (!GetFileTime(handle, &ptr->timeCreation, &ptr->timeLastAccess, |
| 92 | &ptr->timeLastWrite)) { |
| 93 | return cmsys::Status::Windows_GetLastError(); |
| 94 | } |
| 95 | #else |
| 96 | struct stat st; |
| 97 | if (stat(fileName.c_str(), &st) < 0) { |
| 98 | return cmsys::Status::POSIX_errno(); |
| 99 | } |
| 100 | ptr->timeBuf.actime = st.st_atime; |
| 101 | ptr->timeBuf.modtime = st.st_mtime; |
| 102 | #endif |
| 103 | // Accept times |
| 104 | this->times = std::move(ptr); |
| 105 | return cmsys::Status::Success(); |
| 106 | } |
| 107 | |
| 108 | cmsys::Status cmFileTimes::Store(std::string const& fileName) const |
| 109 | { |