summaryrefslogtreecommitdiff
path: root/system/gd/os/linux_generic/files.cc
diff options
context:
space:
mode:
authorScott Lobdell <slobdell@google.com>2022-03-11 19:27:17 +0000
committerScott Lobdell <slobdell@google.com>2022-03-11 19:57:09 +0000
commitc9218ef1b82430a07d94f74c212a30e7ccc52975 (patch)
tree241b7fdeb6bdf1cf3af925ba8996f18faa8973d9 /system/gd/os/linux_generic/files.cc
parenta26bda4d37221f2f7ef750b413502091e3bcddd4 (diff)
parent480d2270b269a0e47bf475eb439111f3f966e2a9 (diff)
Merge TP1A.220225.003
Change-Id: Id71ac466dbfe3707fe2e544ce22b1da8f474ec2b
Diffstat (limited to 'system/gd/os/linux_generic/files.cc')
-rw-r--r--system/gd/os/linux_generic/files.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/system/gd/os/linux_generic/files.cc b/system/gd/os/linux_generic/files.cc
index bb018bf374..cf1a4aade8 100644
--- a/system/gd/os/linux_generic/files.cc
+++ b/system/gd/os/linux_generic/files.cc
@@ -195,5 +195,19 @@ bool RemoveFile(const std::string& path) {
return true;
}
+std::optional<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> FileCreatedTime(
+ const std::string& path) {
+ struct stat file_info;
+ if (stat(path.c_str(), &file_info) != 0) {
+ LOG_ERROR("unable to read '%s' file metadata, error: %s", path.c_str(), strerror(errno));
+ return std::nullopt;
+ }
+ using namespace std::chrono;
+ using namespace std::chrono_literals;
+ auto created_ts = file_info.st_ctim;
+ auto d = seconds{created_ts.tv_sec} + nanoseconds{created_ts.tv_nsec};
+ return time_point<system_clock>(duration_cast<system_clock::duration>(d));
+}
+
} // namespace os
} // namespace bluetooth \ No newline at end of file