source: imaps-frontend/node_modules/@parcel/watcher/src/shared/BruteForceBackend.cc@ 0c6b92a

main
Last change on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include <string>
2#include "../DirTree.hh"
3#include "../Event.hh"
4#include "./BruteForceBackend.hh"
5
6std::shared_ptr<DirTree> BruteForceBackend::getTree(WatcherRef watcher, bool shouldRead) {
7 auto tree = DirTree::getCached(watcher->mDir);
8
9 // If the tree is not complete, read it if needed.
10 if (!tree->isComplete && shouldRead) {
11 readTree(watcher, tree);
12 tree->isComplete = true;
13 }
14
15 return tree;
16}
17
18void BruteForceBackend::writeSnapshot(WatcherRef watcher, std::string *snapshotPath) {
19 std::unique_lock<std::mutex> lock(mMutex);
20 auto tree = getTree(watcher);
21 FILE *f = fopen(snapshotPath->c_str(), "w");
22 if (!f) {
23 throw std::runtime_error(std::string("Unable to open snapshot file: ") + strerror(errno));
24 }
25
26 tree->write(f);
27 fclose(f);
28}
29
30void BruteForceBackend::getEventsSince(WatcherRef watcher, std::string *snapshotPath) {
31 std::unique_lock<std::mutex> lock(mMutex);
32 FILE *f = fopen(snapshotPath->c_str(), "r");
33 if (!f) {
34 throw std::runtime_error(std::string("Unable to open snapshot file: ") + strerror(errno));
35 }
36
37 DirTree snapshot{watcher->mDir, f};
38 auto now = getTree(watcher);
39 now->getChanges(&snapshot, watcher->mEvents);
40 fclose(f);
41}
Note: See TracBrowser for help on using the repository browser.