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"}});
+16 -4
View File
@@ -1747,7 +1747,11 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
? std::format(",\"file\":{}", Util::json_quote(*opts.file_filter_arg))
: std::string{});
} else if (sub == "watch_poll") {
request_json = R"({"op":"watch_poll"})";
request_json =
opts.prefix_arg
? std::format(R"({{"op":"watch_poll","prefix":{}}})",
Util::json_quote(*opts.prefix_arg))
: std::string{R"({"op":"watch_poll"})"};
} else if (sub == "watch_wait") {
std::int64_t timeout_ms = 0;
const auto [ptr, ec] =
@@ -1759,7 +1763,10 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
<< "' (0..5000)\n";
return 2;
}
request_json = std::format(R"({{"op":"watch_wait","timeout_ms":{}}})", timeout_ms);
request_json = std::format(
R"({{"op":"watch_wait","timeout_ms":{}{}}})", timeout_ms,
opts.prefix_arg ? std::format(",\"prefix\":{}", Util::json_quote(*opts.prefix_arg))
: std::string{});
} else if (sub == "ide_generate") {
if (opts.profile_arg.empty()) {
std::cerr << "vbs daemon ide generate: --profile must not be empty\n";
@@ -2863,11 +2870,16 @@ int main(int argc, char **argv) {
auto &daemon_ide_poll_cmd = daemon_ide_cmd.subcommand(
"poll", "Poll pending project file changes (editor extension protocol)");
configure_daemon_common(daemon_ide_poll_cmd);
daemon_ide_poll_cmd.option("--prefix", "", "Only report changed paths under this prefix",
daemon_opts.prefix_arg);
auto &daemon_ide_wait_cmd = daemon_ide_cmd.subcommand(
"wait", "Long-poll for project file changes (bounded, editor extension protocol)");
configure_daemon_common(daemon_ide_wait_cmd);
daemon_ide_wait_cmd.option_default("--timeout-ms", "", "Maximum wait in milliseconds (0..5000)",
daemon_opts.timeout_ms_arg, "2000");
daemon_ide_wait_cmd
.option_default("--timeout-ms", "", "Maximum wait in milliseconds (0..5000)",
daemon_opts.timeout_ms_arg, "2000")
.option("--prefix", "", "Only report changed paths under this prefix",
daemon_opts.prefix_arg);
auto &daemon_ide_generate_cmd =
daemon_ide_cmd.subcommand("generate", "Write editor configuration files");
configure_daemon_common(daemon_ide_generate_cmd);