Skip to content

Commit

Permalink
Use temporary file approach instead
Browse files Browse the repository at this point in the history
  • Loading branch information
yamadapc committed May 28, 2024
1 parent 99abe49 commit c254d7f
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/watchman/WatchmanBackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,20 @@ std::string WatchmanBackend::clock(Watcher &watcher) {
return found->second.stringValue();
}

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

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");
auto clockValue = clock(watcher);
auto temporaryDirectory = std::filesystem::temp_directory_path();
auto temporaryFilePath = temporaryDirectory.append("tmp-parcel-snapshot.txt");
{
std::ofstream ofs(temporaryFilePath);
std::ofstream ofs(*snapshotPath);
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 c254d7f

Please sign in to comment.