路泰科技体检小程序UI设计新版本
1
wwl
2025-07-30 61b58bd03d04d2eb50ac2d93a188c819fe67e01e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <string>
#include "../DirTree.hh"
#include "../Event.hh"
#include "./BruteForceBackend.hh"
 
std::shared_ptr<DirTree> BruteForceBackend::getTree(WatcherRef watcher, bool shouldRead) {
  auto tree = DirTree::getCached(watcher->mDir);
 
  // If the tree is not complete, read it if needed.
  if (!tree->isComplete && shouldRead) {
    readTree(watcher, tree);
    tree->isComplete = true;
  }
 
  return tree;
}
 
void BruteForceBackend::writeSnapshot(WatcherRef watcher, std::string *snapshotPath) {
  std::unique_lock<std::mutex> lock(mMutex);
  auto tree = getTree(watcher);
  FILE *f = fopen(snapshotPath->c_str(), "w");
  if (!f) {
    throw std::runtime_error(std::string("Unable to open snapshot file: ") + strerror(errno));
  }
 
  tree->write(f);
  fclose(f);
}
 
void BruteForceBackend::getEventsSince(WatcherRef watcher, std::string *snapshotPath) {
  std::unique_lock<std::mutex> lock(mMutex);
  FILE *f = fopen(snapshotPath->c_str(), "r");
  if (!f) {
    throw std::runtime_error(std::string("Unable to open snapshot file: ") + strerror(errno));
  }
 
  DirTree snapshot{watcher->mDir, f};
  auto now = getTree(watcher);
  now->getChanges(&snapshot, watcher->mEvents);
  fclose(f);
}