diff --git a/common/remote_file_oss.cc b/common/remote_file_oss.cc index 2ea73afe..d9300def 100644 --- a/common/remote_file_oss.cc +++ b/common/remote_file_oss.cc @@ -247,15 +247,9 @@ absl::Status RemotePathTouchExistingFile(std::string_view path) { return absl::InvalidArgumentError( absl::StrCat("path: ", std::string(path), " does not exist.")); } - std::error_code error; - std::filesystem::last_write_time( - path, std::filesystem::file_time_type::clock::now(), error); - if (error) { - return absl::UnknownError(absl::StrCat( - "filesystem::last_write_time() failed, path: ", std::string(path), - ", error: ", error.message())); - } - return absl::OkStatus(); + if (0 == utimes(path.data(), nullptr)) return absl::OkStatus(); + return absl::InternalError( + absl::StrCat("Failed to set mtime for ", path, " (errno ", errno, ").")); } absl::Status RemotePathDelete(std::string_view path, bool recursively) { diff --git a/common/remote_file_test.cc b/common/remote_file_test.cc index 62694146..e5300795 100644 --- a/common/remote_file_test.cc +++ b/common/remote_file_test.cc @@ -152,13 +152,17 @@ TEST(RemotePathTouchExistingFile, UpdatesTheLastModifiedTime) { const fs::path temp_dir = GetTestTempDir(test_info_->name()); const std::string file_path = temp_dir / "file"; CreateFileOrDie(file_path); + absl::SleepFor(absl::Milliseconds(10)); - const auto start_time = std::filesystem::file_time_type::clock::now(); - absl::SleepFor(absl::Milliseconds(1)); + const auto start_time = absl::Now(); + absl::SleepFor(absl::Milliseconds(10)); ASSERT_TRUE(RemotePathTouchExistingFile(file_path).ok()); - const auto end_time = std::filesystem::file_time_type::clock::now(); + absl::SleepFor(absl::Milliseconds(10)); + const auto end_time = absl::Now(); - const auto last_modified_time = fs::last_write_time(file_path); + struct stat st = {0}; + ASSERT_EQ(lstat(file_path.c_str(), &st), 0); + auto last_modified_time = absl::TimeFromTimespec(st.st_mtim); ASSERT_LT(last_modified_time, end_time); EXPECT_GT(last_modified_time, start_time); }