main
Last change
on this file was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago |
Pred finalna verzija
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[0c6b92a] | 1 | #ifndef DIR_TREE_H
|
---|
| 2 | #define DIR_TREE_H
|
---|
| 3 |
|
---|
| 4 | #include <string>
|
---|
| 5 | #include <unordered_map>
|
---|
| 6 | #include <memory>
|
---|
| 7 | #include "Event.hh"
|
---|
| 8 |
|
---|
| 9 | #ifdef _WIN32
|
---|
| 10 | #define DIR_SEP "\\"
|
---|
| 11 | #else
|
---|
| 12 | #define DIR_SEP "/"
|
---|
| 13 | #endif
|
---|
| 14 |
|
---|
| 15 | struct DirEntry {
|
---|
| 16 | std::string path;
|
---|
| 17 | uint64_t mtime;
|
---|
| 18 | bool isDir;
|
---|
| 19 | mutable void *state;
|
---|
| 20 |
|
---|
| 21 | DirEntry(std::string p, uint64_t t, bool d);
|
---|
| 22 | DirEntry(FILE *f);
|
---|
| 23 | void write(FILE *f) const;
|
---|
| 24 | bool operator==(const DirEntry &other) const {
|
---|
| 25 | return path == other.path;
|
---|
| 26 | }
|
---|
| 27 | };
|
---|
| 28 |
|
---|
| 29 | class DirTree {
|
---|
| 30 | public:
|
---|
| 31 | static std::shared_ptr<DirTree> getCached(std::string root);
|
---|
| 32 | DirTree(std::string root) : root(root), isComplete(false) {}
|
---|
| 33 | DirTree(std::string root, FILE *f);
|
---|
| 34 | DirEntry *add(std::string path, uint64_t mtime, bool isDir);
|
---|
| 35 | DirEntry *find(std::string path);
|
---|
| 36 | DirEntry *update(std::string path, uint64_t mtime);
|
---|
| 37 | void remove(std::string path);
|
---|
| 38 | void write(FILE *f);
|
---|
| 39 | void getChanges(DirTree *snapshot, EventList &events);
|
---|
| 40 |
|
---|
| 41 | std::mutex mMutex;
|
---|
| 42 | std::string root;
|
---|
| 43 | bool isComplete;
|
---|
| 44 | std::unordered_map<std::string, DirEntry> entries;
|
---|
| 45 |
|
---|
| 46 | private:
|
---|
| 47 | DirEntry *_find(std::string path);
|
---|
| 48 | };
|
---|
| 49 |
|
---|
| 50 | #endif
|
---|
Note:
See
TracBrowser
for help on using the repository browser.