Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 705251978
  • Loading branch information
hadi88 authored and copybara-github committed Dec 12, 2024
1 parent 4c740a0 commit a3b81e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
12 changes: 3 additions & 9 deletions common/remote_file_oss.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 8 additions & 4 deletions common/remote_file_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit a3b81e5

Please sign in to comment.