feat(daemon,registry): filter watch events by prefix; answer OPTIONS
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 7s

This commit is contained in:
faumaray committed 2026-12-04 06:30:05 +03:00
1 parent e7698a411d
commit e61eff7a8f
9 files changed
+208 -11

No files matched your search

+44 -4
View File
@@ -1894,6 +1894,9 @@ struct DaemonServer::Impl {
[[nodiscard]] std::string status_response() const;
DispatchResult dispatch(std::string_view line);
void record_watch_batch(const Watch::WatchBatch &batch);
// Removes and returns buffered changes matching `prefix` (all when empty); non-matching
// entries stay buffered for later requests.
std::vector<std::filesystem::path> take_pending(std::string_view prefix);
void close_socket() noexcept {
if (listen_fd >= 0) {
@@ -1961,6 +1964,25 @@ void DaemonServer::Impl::record_watch_batch(const Watch::WatchBatch &batch) {
}
}
std::vector<std::filesystem::path> DaemonServer::Impl::take_pending(std::string_view prefix) {
if (prefix.empty()) {
std::vector<std::filesystem::path> taken;
taken.swap(pending_changes);
return taken;
}
std::vector<std::filesystem::path> taken;
std::vector<std::filesystem::path> kept;
for (auto &path : pending_changes) {
if (std::string_view{path.string()}.starts_with(prefix)) {
taken.push_back(std::move(path));
} else {
kept.push_back(std::move(path));
}
}
pending_changes = std::move(kept);
return taken;
}
std::string DaemonServer::Impl::status_response() const {
const DaemonStatus status = current_status();
JsonValue::Object object;
@@ -2010,11 +2032,18 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
return {error_response(std::format("watch_poll: {}", batch.error().format())), false};
}
record_watch_batch(*batch);
std::string prefix;
if (const auto entry = object->find("prefix"); entry != object->end()) {
const auto *value = std::get_if<std::string>(&entry->second.value);
if (value == nullptr || value->size() > 4096) {
return {error_response("\"prefix\" must be a bounded string"), false};
}
prefix = *value;
}
JsonValue::Array changed;
for (const auto &path : pending_changes) {
for (const auto &path : take_pending(prefix)) {
changed.emplace_back(path.string());
}
pending_changes.clear();
JsonValue::Object object;
object.emplace("ok", JsonValue{true});
object.emplace("op", JsonValue{std::string{"watch_poll"}});
@@ -2328,6 +2357,15 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
timeout_ms = *value;
}
std::string prefix;
if (const auto entry = object->find("prefix"); entry != object->end()) {
const auto *value = std::get_if<std::string>(&entry->second.value);
if (value == nullptr || value->size() > 4096) {
return {error_response("\"prefix\" must be a bounded string"), false};
}
prefix = *value;
}
bool timed_out = false;
if (pending_changes.empty() && timeout_ms > 0) {
auto batch = watcher.poll_events(std::chrono::milliseconds{timeout_ms},
@@ -2341,10 +2379,12 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
record_watch_batch(*batch);
}
JsonValue::Array changed;
for (const auto &path : pending_changes) {
for (const auto &path : take_pending(prefix)) {
changed.emplace_back(path.string());
}
pending_changes.clear();
if (!prefix.empty() && changed.empty()) {
timed_out = true;
}
JsonValue::Object object;
object.emplace("ok", JsonValue{true});
object.emplace("op", JsonValue{std::string{"watch_wait"}});