static bool parse_relative_root(w_root_t *root, w_query *res, json_t *query) { json_t *relative_root; w_string_t *path, *canon_path; relative_root = json_object_get(query, "relative_root"); if (!relative_root) { return true; } if (!json_is_string(relative_root)) { res->errmsg = strdup("'relative_root' must be a string"); return false; } path = w_string_new(json_string_value(relative_root)); canon_path = w_string_canon_path(path); res->relative_root = w_string_path_cat(root->root_path, canon_path); res->relative_root_slash = w_string_make_printf("%.*s%c", res->relative_root->len, res->relative_root->buf, WATCHMAN_DIR_SEP); w_string_delref(path); w_string_delref(canon_path); return true; }
static bool parse_paths(w_query *res, json_t *query) { json_t *paths; size_t i; paths = json_object_get(query, "path"); if (!paths) { return true; } if (!json_is_array(paths)) { res->errmsg = strdup("'path' must be an array"); return false; } res->npaths = json_array_size(paths); res->paths = calloc(res->npaths, sizeof(res->paths[0])); if (!res->paths) { res->errmsg = strdup("out of memory"); return false; } for (i = 0; i < json_array_size(paths); i++) { json_t *ele = json_array_get(paths, i); const char *name = NULL; w_string_t *path; res->paths[i].depth = -1; if (json_is_string(ele)) { name = json_string_value(ele); } else if (json_unpack(ele, "{s:s, s:i}", "path", &name, "depth", &res->paths[i].depth ) != 0) { res->errmsg = strdup( "expected object with 'path' and 'depth' properties" ); return false; } path = w_string_new(name); res->paths[i].name = w_string_canon_path(path); w_string_delref(path); } return true; }
static void parse_relative_root( const std::shared_ptr<w_root_t>& root, w_query* res, const json_ref& query) { auto relative_root = query.get_default("relative_root"); if (!relative_root) { return; } if (!relative_root.isString()) { throw QueryParseError("'relative_root' must be a string"); } auto path = json_to_w_string(relative_root).normalizeSeparators(); auto canon_path = w_string_canon_path(path); res->relative_root = w_string::pathCat({root->root_path, canon_path}); res->relative_root_slash = w_string::printf("%s/", res->relative_root.c_str()); }