Skip to content

Commit

Permalink
Update to write to a sibling file rather than a tmp one
Browse files Browse the repository at this point in the history
  • Loading branch information
yamadapc committed May 28, 2024
1 parent c313651 commit 99abe49
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/watchman/WatchmanBackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,21 @@ std::string WatchmanBackend::clock(Watcher &watcher) {
return found->second.stringValue();
}

void WatchmanBackend::writeSnapshot(Watcher &watcher, std::string *snapshotPath) {
void WatchmanBackend::writeSnapshot(Watcher &watcher, std::string *inputSnapshotPath) {
std::unique_lock<std::mutex> lock(mMutex);
watchmanWatch(watcher.mDir);

auto clockValue = clock(watcher);
auto temporaryDirectory = std::filesystem::temp_directory_path();
auto temporaryFilePath = temporaryDirectory.append("tmp-parcel-snapshot.txt");
const auto clockValue = clock(watcher);
const auto snapshotPath = std::filesystem::path(*inputSnapshotPath);
auto temporaryFilePath = std::filesystem::path(snapshotPath);
temporaryFilePath.replace_filename(".parcel-temporary-snapshot.txt");
{
std::ofstream ofs(temporaryFilePath);
ofs << clockValue;
ofs.flush();
ofs.close();
}
std::filesystem::rename(temporaryFilePath, *snapshotPath);
std::filesystem::rename(temporaryFilePath, snapshotPath);
}

void WatchmanBackend::getEventsSince(Watcher &watcher, std::string *snapshotPath) {
Expand Down

0 comments on commit 99abe49

Please sign in to comment.