Allow set and get last modified times on files.

PiperOrigin-RevId: 791407269
This commit is contained in:
Francis Tsui
2025-08-05 16:08:30 -07:00
committed by Copybara-Service
parent 09e11ee122
commit 38827f2b4b
11 changed files with 144 additions and 6 deletions
@@ -66,6 +66,7 @@ cc_library(
"//internal/platform/implementation:types",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
],
)
@@ -21,6 +21,8 @@
#include "absl/memory/memory.h"
#include "absl/strings/string_view.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "internal/platform/exception.h"
namespace nearby {
@@ -94,9 +96,13 @@ Exception IOFile::Write(const ByteArray& data) {
return {file_.good() ? Exception::kSuccess : Exception::kIo};
}
Exception IOFile::Flush() {
file_.flush();
return {file_.good() ? Exception::kSuccess : Exception::kIo};
absl::Time IOFile::GetLastModifiedTime() const {
// TODO(ftsui): Implement this method.
return absl::Now();
}
void IOFile::SetLastModifiedTime(absl::Time last_modified_time) {
// TODO(ftsui): Implement this method.
}
} // namespace shared
@@ -15,11 +15,14 @@
#ifndef PLATFORM_IMPL_SHARED_FILE_H_
#define PLATFORM_IMPL_SHARED_FILE_H_
#include <cstddef>
#include <cstdint>
#include <fstream>
#include <memory>
#include <string>
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "internal/platform/exception.h"
#include "internal/platform/implementation/input_file.h"
#include "internal/platform/implementation/output_file.h"
@@ -42,7 +45,9 @@ class IOFile final : public api::InputFile, public api::OutputFile {
Exception Close() override;
Exception Write(const ByteArray& data) override;
Exception Flush() override;
absl::Time GetLastModifiedTime() const override;
void SetLastModifiedTime(absl::Time last_modified_time) override;
private:
explicit IOFile(const absl::string_view file_path, size_t size);