forked from facebook/watchman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener-user.cpp
118 lines (97 loc) · 2.91 KB
/
listener-user.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* Copyright 2012-present Facebook, Inc.
* Licensed under the Apache License, Version 2.0 */
#include "watchman.h"
#include <folly/ScopeGuard.h>
// Functions relating to the per-user service
using namespace watchman;
static void cmd_shutdown(struct watchman_client* client, const json_ref&) {
auto resp = make_response();
logf(ERR, "shutdown-server was requested, exiting!\n");
w_request_shutdown();
resp.set("shutdown-server", json_true());
send_and_dispose_response(client, std::move(resp));
}
W_CMD_REG("shutdown-server", cmd_shutdown, CMD_DAEMON | CMD_POISON_IMMUNE, NULL)
void add_root_warnings_to_response(
json_ref& response,
const std::shared_ptr<w_root_t>& root) {
auto info = root->recrawlInfo.rlock();
if (!info->warning) {
return;
}
response.set(
"warning",
w_string_to_json(w_string::build(
info->warning,
"\n",
"To clear this warning, run:\n"
"`watchman watch-del ",
root->root_path,
" ; watchman watch-project ",
root->root_path,
"`\n")));
}
std::shared_ptr<w_root_t> doResolveOrCreateRoot(
struct watchman_client* client,
const json_ref& args,
bool create) {
const char* root_name;
// Assume root is first element
size_t root_index = 1;
if (args.array().size() <= root_index) {
throw RootResolveError("wrong number of arguments");
}
const auto& ele = args.at(root_index);
root_name = json_string_value(ele);
if (!root_name) {
throw RootResolveError(
"invalid value for argument ",
root_index,
", expected a string naming the root dir");
}
try {
std::shared_ptr<w_root_t> root;
if (client->client_mode) {
root = w_root_resolve_for_client_mode(root_name);
} else {
if (!client->client_is_owner) {
// Only the owner is allowed to create watches
create = false;
}
root = w_root_resolve(root_name, create);
}
if (client->perf_sample) {
client->perf_sample->add_root_meta(root);
}
return root;
} catch (const std::exception& exc) {
throw RootResolveError(
"unable to resolve root ",
root_name,
": ",
exc.what(),
client->client_is_owner
? ""
: " (this may be because you are not the process owner)");
}
}
std::shared_ptr<w_root_t> resolveRoot(
struct watchman_client* client,
const json_ref& args) {
return doResolveOrCreateRoot(client, args, false);
}
std::shared_ptr<w_root_t> resolveOrCreateRoot(
struct watchman_client* client,
const json_ref& args) {
return doResolveOrCreateRoot(client, args, true);
}
watchman_user_client::watchman_user_client(
std::unique_ptr<watchman_stream>&& stm)
: watchman_client(std::move(stm)) {}
watchman_user_client::~watchman_user_client() {
/* cancel subscriptions */
subscriptions.clear();
w_client_vacate_states(this);
}
/* vim:ts=2:sw=2:et:
*/