@@ -55,7 +55,7 @@ void HopperDaemon::handle_endpoint_inotify(struct inotify_event *ev,
5555 p /= ev->name ;
5656
5757 PipeType pipe_type = detect_pipe_type (p);
58- if (pipe_type == PipeType::NONE && std::filesystem::is_directory (p) ) {
58+ if (pipe_type == PipeType::NONE && ev-> mask & IN_ISDIR ) {
5959 // nested endpoint
6060 if (create_endpoint (p) == 0 )
6161 std::cerr << " Endpoint creation failed! Out of IDs?"
@@ -78,13 +78,19 @@ void HopperDaemon::handle_endpoint_inotify(struct inotify_event *ev,
7878 std::filesystem::path p = endpoint->path ();
7979 p /= ev->name ;
8080
81- HopperPipe *pipe = endpoint->pipe_by_path (p);
81+ if (ev->mask & IN_ISDIR) {
82+ // nested endpoint
83+ delete_endpoint (p);
84+ } else {
85+ // pipe
86+ HopperPipe *pipe = endpoint->pipe_by_path (p);
8287
83- if (pipe != nullptr ) {
84- if (pipe->status () == PipeStatus::ACTIVE)
85- remove_pipe (endpoint, pipe->id ());
88+ if (pipe != nullptr ) {
89+ if (pipe->status () == PipeStatus::ACTIVE)
90+ remove_pipe (endpoint, pipe->id ());
8691
87- endpoint->remove_by_id (pipe->id ());
92+ endpoint->remove_by_id (pipe->id ());
93+ }
8894 }
8995 }
9096}
@@ -106,6 +112,11 @@ void HopperDaemon::handle_inotify() {
106112 continue ;
107113 }
108114
115+ if (iev->mask & IN_IGNORED) {
116+ // the endpoint probably got deleted, ignore
117+ continue ;
118+ }
119+
109120 HopperEndpoint *endpoint = endpoint_by_watch (iev->wd );
110121 if (endpoint == nullptr ) {
111122 std::cout << " No endpoint found for watch ID " << iev->wd
@@ -114,10 +125,6 @@ void HopperDaemon::handle_inotify() {
114125 }
115126
116127 handle_endpoint_inotify (iev, endpoint);
117-
118- // The endpoint is now closed
119- if (iev->mask & IN_IGNORED)
120- delete_endpoint (endpoint->id ());
121128 }
122129}
123130
0 commit comments