diff --git a/src/watchman/WatchmanBackend.cc b/src/watchman/WatchmanBackend.cc index 04640037..6044c85f 100644 --- a/src/watchman/WatchmanBackend.cc +++ b/src/watchman/WatchmanBackend.cc @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "../DirTree.hh" #include "../Event.hh" @@ -241,8 +242,16 @@ void WatchmanBackend::writeSnapshot(Watcher &watcher, std::string *snapshotPath) std::unique_lock lock(mMutex); watchmanWatch(watcher.mDir); - std::ofstream ofs(*snapshotPath); - ofs << clock(watcher); + auto clockValue = clock(watcher); + auto temporaryDirectory = std::filesystem::temp_directory_path(); + auto temporaryFilePath = temporaryDirectory.append("tmp-parcel-snapshot.txt"); + { + std::ofstream ofs(temporaryFilePath); + ofs << clockValue; + ofs.flush(); + ofs.close(); + } + std::filesystem::rename(temporaryFilePath, *snapshotPath); } void WatchmanBackend::getEventsSince(Watcher &watcher, std::string *snapshotPath) { diff --git a/test/since.js b/test/since.js index c3db9990..0cccee79 100644 --- a/test/since.js +++ b/test/since.js @@ -68,7 +68,7 @@ describe('since', () => { describe('files', () => { it('should emit when a file is created', async function () { - this.timeout(5000); + this.timeout(10000); let f = getFilename(); await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); if (isSecondPrecision) {