forked from facebook/watchman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch.c
125 lines (103 loc) · 2.96 KB
/
watch.c
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
119
120
121
122
123
124
125
/* Copyright 2013-present Facebook, Inc.
* Licensed under the Apache License, Version 2.0 */
#include "watchman.h"
bool w_cmd_realpath_root(json_t *args, char **errmsg)
{
const char *path;
char *resolved;
if (json_array_size(args) < 2) {
ignore_result(asprintf(errmsg, "wrong number of arguments"));
return false;
}
path = json_string_value(json_array_get(args, 1));
if (!path) {
ignore_result(asprintf(errmsg, "second argument must be a string"));
return false;
}
resolved = w_realpath(path);
if (resolved) {
json_array_set_new(args, 1, json_string_nocheck(resolved));
}
return true;
}
/* clock /root
* Returns the current clock value for a watched root
*/
static void cmd_clock(struct watchman_client *client, json_t *args)
{
w_root_t *root;
json_t *resp;
/* resolve the root */
if (json_array_size(args) != 2) {
send_error_response(client, "wrong number of arguments to 'clock'");
return;
}
root = resolve_root_or_err(client, args, 1, false);
if (!root) {
return;
}
resp = make_response();
w_root_lock(root);
annotate_with_clock(root, resp);
w_root_unlock(root);
send_and_dispose_response(client, resp);
w_root_delref(root);
}
W_CMD_REG("clock", cmd_clock, CMD_DAEMON, w_cmd_realpath_root)
/* watch-del /root
* Stops watching the specified root */
static void cmd_watch_delete(struct watchman_client *client, json_t *args)
{
w_root_t *root;
json_t *resp;
/* resolve the root */
if (json_array_size(args) != 2) {
send_error_response(client, "wrong number of arguments to 'watch-del'");
return;
}
root = resolve_root_or_err(client, args, 1, false);
if (!root) {
return;
}
resp = make_response();
set_prop(resp, "watch-del", json_boolean(w_root_stop_watch(root)));
set_prop(resp, "root", json_string_nocheck(root->root_path->buf));
send_and_dispose_response(client, resp);
w_root_delref(root);
}
W_CMD_REG("watch-del", cmd_watch_delete, CMD_DAEMON, w_cmd_realpath_root)
/* watch-list
* Returns a list of watched roots */
static void cmd_watch_list(struct watchman_client *client, json_t *args)
{
json_t *resp;
json_t *root_paths;
unused_parameter(args);
resp = make_response();
root_paths = w_root_watch_list_to_json();
set_prop(resp, "roots", root_paths);
send_and_dispose_response(client, resp);
}
W_CMD_REG("watch-list", cmd_watch_list, CMD_DAEMON, NULL)
/* watch /root */
static void cmd_watch(struct watchman_client *client, json_t *args)
{
w_root_t *root;
json_t *resp;
/* resolve the root */
if (json_array_size(args) != 2) {
send_error_response(client, "wrong number of arguments to 'watch'");
return;
}
root = resolve_root_or_err(client, args, 1, true);
if (!root) {
return;
}
resp = make_response();
set_prop(resp, "watch", json_string_nocheck(root->root_path->buf));
send_and_dispose_response(client, resp);
w_root_delref(root);
}
W_CMD_REG("watch", cmd_watch, CMD_DAEMON, w_cmd_realpath_root)
/* vim:ts=2:sw=2:et:
*/