| 24 | } |
| 25 | |
| 26 | void InotifyEventLoop::work() { |
| 27 | char buffer[BUFFER_SIZE]; |
| 28 | inotify_event *event = NULL; |
| 29 | unsigned int bytesRead, position = 0; |
| 30 | bool isDirectoryEvent = false, isDirectoryRemoval = false; |
| 31 | InotifyService *inotifyService = mInotifyService; |
| 32 | InotifyRenameEvent renameEvent; |
| 33 | renameEvent.isStarted = false; |
| 34 | |
| 35 | auto create = [&event, &isDirectoryEvent, &inotifyService]() { |
| 36 | if (event == NULL) { |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | if (isDirectoryEvent) { |
| 41 | inotifyService->createDirectory(event->wd, event->len > 0 ? event->name : ""); |
| 42 | } else { |
| 43 | inotifyService->create(event->wd, event->len > 0 ? event->name : ""); |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | auto modify = [&event, &isDirectoryEvent, &inotifyService]() { |
| 48 | if (event == NULL) { |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | inotifyService->modify(event->wd, event->len > 0 ? event->name : ""); |
| 53 | }; |
| 54 | |
| 55 | auto remove = [&event, &isDirectoryRemoval, &inotifyService]() { |
| 56 | if (event == NULL) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | if (isDirectoryRemoval) { |
| 61 | inotifyService->removeDirectory(event->wd); |
| 62 | } else { |
| 63 | inotifyService->remove(event->wd, event->len > 0 ? event->name : ""); |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | auto renameStart = [&event, &isDirectoryEvent, &renameEvent]() { |
| 68 | renameEvent.cookie = event->cookie; |
| 69 | renameEvent.isDirectory = isDirectoryEvent; |
| 70 | renameEvent.name = event->len > 0 ? event->name : ""; |
| 71 | renameEvent.wd = event->wd; |
| 72 | renameEvent.isStarted = true; |
| 73 | }; |
| 74 | |
| 75 | auto renameEnd = [&create, &event, &inotifyService, &isDirectoryRemoval, &renameEvent]() { |
| 76 | if (!renameEvent.isStarted) { |
| 77 | create(); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | if (renameEvent.cookie != event->cookie) { |
| 82 | if (isDirectoryRemoval) { |
| 83 | inotifyService->removeDirectory(renameEvent.wd); |
no test coverage detected