szaszm commented on code in PR #1634:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1634#discussion_r1310492843
##########
libminifi/src/utils/file/FileUtils.cpp:
##########
@@ -96,4 +100,22 @@ std::filesystem::file_time_type
from_sys(std::chrono::system_clock::time_point s
#endif
}
+#ifdef WIN32
+std::chrono::file_clock::time_point fileTimePointFromFileTime(const FILETIME&
filetime) {
+ static_assert(std::ratio_equal_v<std::chrono::file_clock::duration::period,
std::ratio<1, 10000000>>, "file_clock duration must be 100 nanoseconds");
+ std::chrono::file_clock::duration
duration{(static_cast<int64_t>(filetime.dwHighDateTime) << 32) |
filetime.dwLowDateTime};
+ return std::chrono::file_clock::time_point{duration};
+}
+
+nonstd::expected<WindowsFileTimes, std::error_code> getWindowsFileTimes(const
std::filesystem::path& path) {
+ WIN32_FILE_ATTRIBUTE_DATA file_attributes;
+ auto get_file_attributes_result = GetFileAttributesExW(path.c_str(),
GetFileExInfoStandard, &file_attributes);
+ if (!get_file_attributes_result)
+ return
nonstd::make_unexpected(utils::OsUtils::windowsErrorToErrorCode(GetLastError()));
+ return WindowsFileTimes{.creation_time =
fileTimePointFromFileTime(file_attributes.ftCreationTime),
+ .last_access_time =
fileTimePointFromFileTime(file_attributes.ftLastAccessTime),
+ .last_write_time =
fileTimePointFromFileTime(file_attributes.ftLastWriteTime)};
+}
Review Comment:
I just don't like OS-specific utilities, when the OS-independent doesn't
take significantly more effort, especially when it comes to interface
definition.
POSIX doesn't provide the creation time, but Linux provides a "birth time"
with certain filesystems. See
[statx](https://man7.org/linux/man-pages/man2/statx.2.html) (Linux-only).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]