| 252 | } |
| 253 | |
| 254 | void Add(std::shared_ptr<Dirent> dirent) override |
| 255 | { |
| 256 | auto parent = Find(dirent->path.parent()); |
| 257 | if (!parent) |
| 258 | return; |
| 259 | |
| 260 | /* Add the actual item (the easy bit). */ |
| 261 | |
| 262 | auto node = std::make_shared<FilesystemNode>(dirent); |
| 263 | _byItem[node->item] = node; |
| 264 | parent->children[dirent->filename] = node; |
| 265 | ItemAdded(parent->item, node->item); |
| 266 | |
| 267 | /* If this is a new directory, add the stub item to it. */ |
| 268 | |
| 269 | if (dirent->file_type == TYPE_DIRECTORY) |
| 270 | { |
| 271 | auto stub = |
| 272 | std::make_shared<FilesystemNode>(std::make_shared<Dirent>()); |
| 273 | _byItem[stub->item] = stub; |
| 274 | node->children[""] = stub; |
| 275 | stub->stub = true; |
| 276 | stub->dirent->path = dirent->path; |
| 277 | stub->dirent->path.push_back(""); |
| 278 | ItemAdded(node->item, stub->item); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | private: |
| 283 | std::shared_ptr<FilesystemNode> _root; |
no test coverage detected