* InotifyTree --------------------------------------------------------------------------------------------------------- */
| 8 | * InotifyTree --------------------------------------------------------------------------------------------------------- |
| 9 | */ |
| 10 | InotifyTree::InotifyTree(int inotifyInstance, std::string path, const std::vector<std::string> &excludedPaths): |
| 11 | mError(""), |
| 12 | mInotifyInstance(inotifyInstance) { |
| 13 | mInotifyNodeByWatchDescriptor = new std::map<int, InotifyNode *>; |
| 14 | std::string directory; |
| 15 | std::string watchName; |
| 16 | mExcludedPaths = excludedPaths; |
| 17 | if (path.length() == 1 && path[0] == '/') { |
| 18 | directory = ""; |
| 19 | watchName = ""; |
| 20 | } else { |
| 21 | uint32_t location = path.find_last_of("/"); |
| 22 | directory = (location == 0) ? "" : path.substr(0, location); |
| 23 | watchName = path.substr(location + 1); |
| 24 | } |
| 25 | |
| 26 | mWatchedPath = directory + "/" + watchName; |
| 27 | |
| 28 | struct stat file; |
| 29 | if (stat(mWatchedPath.c_str(), &file) < 0) { |
| 30 | mRoot = NULL; |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | mRoot = new InotifyNode( |
| 35 | this, |
| 36 | mInotifyInstance, |
| 37 | NULL, |
| 38 | directory, |
| 39 | watchName, |
| 40 | file.st_ino |
| 41 | ); |
| 42 | addInode(file.st_ino, mRoot); |
| 43 | |
| 44 | if (!mRoot->isAlive()) { |
| 45 | delete mRoot; |
| 46 | mRoot = NULL; |
| 47 | return; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | bool InotifyTree::existWatchedPath() { |
| 52 | struct stat file; |