Skip to content

Commit b42955a

Browse files
authored
Merge pull request #8 from systemetric/delete-fix
fix(daemon): correctly handle endpoint deletion
2 parents 3507098 + c8516b7 commit b42955a

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

daemon/daemon_endpoint.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ void HopperDaemon::delete_endpoint(uint32_t id) {
5555

5656
std::cout << "DELETE " << *(m_endpoints[id]) << std::endl;
5757

58+
inotify_rm_watch(m_inotify_fd, m_endpoints[id]->watch_fd());
59+
5860
delete m_endpoints[id];
5961
m_endpoints.erase(id);
6062
}

daemon/daemon_inotify.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)