forked from twitter/libwatchman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchman.h
328 lines (301 loc) · 9.42 KB
/
watchman.h
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#ifndef LIBWATCHMAN_WATCHMAN_H_
#define LIBWATCHMAN_WATCHMAN_H_
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
enum watchman_fields {
WATCHMAN_FIELD_NAME = 0x00000001,
WATCHMAN_FIELD_EXISTS = 0x00000002,
WATCHMAN_FIELD_CCLOCK = 0x00000004,
WATCHMAN_FIELD_OCLOCK = 0x00000008,
WATCHMAN_FIELD_CTIME = 0x00000010,
WATCHMAN_FIELD_CTIME_MS = 0x00000020,
WATCHMAN_FIELD_CTIME_US = 0x00000040,
WATCHMAN_FIELD_CTIME_NS = 0x00000080,
WATCHMAN_FIELD_CTIME_F = 0x00000100,
WATCHMAN_FIELD_MTIME = 0x00000200,
WATCHMAN_FIELD_MTIME_MS = 0x00000400,
WATCHMAN_FIELD_MTIME_US = 0x00000800,
WATCHMAN_FIELD_MTIME_NS = 0x00001000,
WATCHMAN_FIELD_MTIME_F = 0x00002000,
WATCHMAN_FIELD_SIZE = 0x00004000,
WATCHMAN_FIELD_UID = 0x00008000,
WATCHMAN_FIELD_GID = 0x00010000,
WATCHMAN_FIELD_INO = 0x00020000,
WATCHMAN_FIELD_DEV = 0x00040000,
WATCHMAN_FIELD_NLINK = 0x00080000,
WATCHMAN_FIELD_NEWER = 0x00100000, /* corresponds to "new" */
WATCHMAN_FIELD_MODE = 0x00200000,
WATCHMAN_FIELD_END = 0x00400000
};
struct watchman_connection {
FILE *fp;
};
enum watchman_expression_type {
WATCHMAN_EXPR_TY_ALLOF,
WATCHMAN_EXPR_TY_ANYOF,
WATCHMAN_EXPR_TY_NOT,
WATCHMAN_EXPR_TY_TRUE,
WATCHMAN_EXPR_TY_FALSE,
WATCHMAN_EXPR_TY_SINCE,
WATCHMAN_EXPR_TY_SUFFIX,
WATCHMAN_EXPR_TY_MATCH,
WATCHMAN_EXPR_TY_IMATCH,
WATCHMAN_EXPR_TY_PCRE,
WATCHMAN_EXPR_TY_IPCRE,
WATCHMAN_EXPR_TY_NAME,
WATCHMAN_EXPR_TY_INAME,
WATCHMAN_EXPR_TY_TYPE,
WATCHMAN_EXPR_TY_EMPTY,
WATCHMAN_EXPR_TY_EXISTS
};
enum watchman_error_code {
WATCHMAN_ERR_CONNECT = 1024,
WATCHMAN_ERR_TIMEOUT,
WATCHMAN_ERR_RUN_WATCHMAN,
WATCHMAN_ERR_WATCHMAN_BROKEN,
WATCHMAN_ERR_WATCHMAN_REPORTED,
/* We only want to have codes for the errors that
* callers might find interesting*/
WATCHMAN_ERR_OTHER,
/* Possibly in addition to another error, we couldn't get back to
* our initial working directory */
WATCHMAN_ERR_CWD = 2048
};
struct watchman_error {
char *message;
enum watchman_error_code code;
int err_no;
};
enum watchman_clockspec {
WATCHMAN_CLOCKSPEC_DEFAULT = 0,
WATCHMAN_CLOCKSPEC_OCLOCK,
WATCHMAN_CLOCKSPEC_CCLOCK,
WATCHMAN_CLOCKSPEC_MTIME,
WATCHMAN_CLOCKSPEC_CTIME
};
enum watchman_basename {
WATCHMAN_BASENAME_DEFAULT,
WATCHMAN_BASENAME_BASENAME,
WATCHMAN_BASENAME_WHOLENAME
};
struct watchman_expression;
struct watchman_since_expr {
unsigned is_str:1;
union {
char *since;
time_t time;
} t;
enum watchman_clockspec clockspec;
};
struct watchman_suffix_expr {
char *suffix;
};
struct watchman_match_expr {
char *match;
enum watchman_basename basename;
};
struct watchman_name_expr {
int nr;
char **names;
enum watchman_basename basename;
};
struct watchman_type_expr {
char type;
};
struct watchman_not_expr {
struct watchman_expression *clause;
};
struct watchman_union_expr {
int nr;
struct watchman_expression **clauses;
};
/* These are the possible fields that can be returned by watchman
query. Only fields that you request will be set (if you don't
request any, then watchman's default will be used). */
struct watchman_stat {
time_t ctime;
int64_t ctime_ms;
int64_t ctime_us;
int64_t ctime_ns;
double ctime_f;
dev_t dev;
gid_t gid;
int ino;
int mode;
time_t mtime;
int64_t mtime_ms;
int64_t mtime_us;
int64_t mtime_ns;
double mtime_f;
unsigned newer:1;
unsigned exists:1;
int nlink;
uid_t uid;
char *name;
char *oclock;
char *cclock;
off_t size;
};
struct watchman_query_result {
char *version;
char *clock;
unsigned is_fresh_instance:1;
int nr;
struct watchman_stat *stats;
};
struct watchman_watch_list {
int nr;
char **roots;
};
struct watchman_pathspec {
int depth;
char *path;
};
struct watchman_query {
unsigned since_is_str:1;
unsigned all:1;
unsigned empty_on_fresh:1;
union {
char *str;
time_t time;
} s;
int nr_suffixes;
int cap_suffixes;
char **suffixes;
int nr_paths;
int cap_paths;
struct watchman_pathspec *paths;
int fields;
/* negative for unset */
int64_t sync_timeout;
};
struct watchman_expression {
enum watchman_expression_type ty;
union {
struct watchman_union_expr union_expr;
struct watchman_not_expr not_expr;
struct watchman_since_expr since_expr;
struct watchman_suffix_expr suffix_expr;
struct watchman_match_expr match_expr;
struct watchman_name_expr name_expr;
struct watchman_type_expr type_expr;
/* true, false, empty, and exists don't need any extra data */
} e;
};
struct watchman_version {
int major;
int minor;
int micro;
};
struct watchman_connection *
watchman_connect(struct timeval timeout, struct watchman_error *error);
int
watchman_watch(struct watchman_connection *connection, const char *path,
struct watchman_error *error);
int
watchman_watch_del(struct watchman_connection *connection, const char *path,
struct watchman_error *error);
struct watchman_watch_list *
watchman_watch_list(struct watchman_connection *connection,
struct watchman_error *error);
struct watchman_expression *
watchman_since_expression(const char *since, enum watchman_clockspec spec);
struct watchman_expression *
watchman_since_expression_time_t(time_t time, enum watchman_clockspec spec);
struct watchman_expression *
watchman_not_expression(struct watchman_expression *expression);
struct watchman_expression *
watchman_allof_expression(int nr, struct watchman_expression **expressions);
struct watchman_expression *
watchman_anyof_expression(int nr, struct watchman_expression **expressions);
struct watchman_expression *
watchman_empty_expression(void);
struct watchman_expression *
watchman_true_expression(void);
struct watchman_expression *
watchman_false_expression(void);
struct watchman_expression *
watchman_exists_expression(void);
struct watchman_expression *
watchman_suffix_expression(const char *suffix);
struct watchman_expression *
watchman_match_expression(const char *match, enum watchman_basename basename);
struct watchman_expression *
watchman_imatch_expression(const char *match, enum watchman_basename basename);
struct watchman_expression *
watchman_pcre_expression(const char *match, enum watchman_basename basename);
struct watchman_expression *
watchman_ipcre_expression(const char *match, enum watchman_basename basename);
struct watchman_expression *
watchman_name_expression(const char *match, enum watchman_basename basename);
struct watchman_expression *
watchman_iname_expression(const char *match, enum watchman_basename basename);
struct watchman_expression *
watchman_names_expression(int nr, char const **match,
enum watchman_basename basename);
struct watchman_expression *
watchman_inames_expression(int nr, char const **match,
enum watchman_basename basename);
struct watchman_expression *
watchman_type_expression(char c);
struct watchman_query_result *
watchman_do_query(struct watchman_connection *connection, const char *fs_path,
const struct watchman_query *query,
const struct watchman_expression *expr,
struct watchman_error *error);
struct watchman_query_result *
watchman_do_query_timeout(struct watchman_connection *conn,
const char *fs_path,
const struct watchman_query *query,
const struct watchman_expression *expr,
struct timeval *timeout,
struct watchman_error *error);
struct watchman_query *
watchman_query(void);
void
watchman_query_add_suffix(struct watchman_query *query, const char *suffix);
void
watchman_query_add_path(struct watchman_query *query, const char *path, int depth);
void
watchman_query_set_since_oclock(struct watchman_query *query, const char *since);
void
watchman_query_set_since_time_t(struct watchman_query *query, time_t since);
void
watchman_query_set_fields(struct watchman_query *query, int fields);
void
watchman_query_set_empty_on_fresh(struct watchman_query *query,
bool empty_on_fresh);
void
watchman_free_expression(struct watchman_expression *expr);
void
watchman_free_query_result(struct watchman_query_result *res);
void
watchman_free_query(struct watchman_query *query);
void
watchman_free_watch_list(struct watchman_watch_list *list);
void
watchman_release_error(struct watchman_error *error);
void
watchman_connection_close(struct watchman_connection *connection);
int
watchman_recrawl(struct watchman_connection *connection, const char *path,
struct watchman_error *error);
char *
watchman_clock(struct watchman_connection *conn,
const char *path,
unsigned int sync_timeout,
struct watchman_error *error);
int
watchman_version(struct watchman_connection *conn,
struct watchman_error *error,
struct watchman_version* version);
int
watchman_shutdown_server(struct watchman_connection *conn,
struct watchman_error *error);
int
is_watchman_error(struct watchman_error *error);
#endif /* LIBWATCHMAN_WATCHMAN_H */