Exemple #1
0
static bool eval_size(struct w_query_ctx *ctx, struct watchman_file *file,
    void *data)
{
  struct w_query_int_compare *comp = data;
  unused_parameter(ctx);

  // Removed files never evaluate true
  if (!file->exists) {
    return false;
  }

  return eval_int_compare(file->stat.size, comp);
}
Exemple #2
0
static bool eval_dirname(struct w_query_ctx *ctx,
                         struct watchman_file *file, void *ptr) {
    struct dirname_data *data = ptr;
    w_string_t *str = w_query_ctx_get_wholename(ctx);
    json_int_t depth = 0;
    size_t i;

    unused_parameter(file);

    if (str->len <= data->dirname->len) {
        // Either it doesn't prefix match, or file name is == dirname.
        // That means that the best case is that the wholename matches.
        // we only want to match if dirname(wholename) matches, so it
        // is not possible for us to match unless the length of wholename
        // is greater than the dirname operand
        return false;
    }

    // Want to make sure that wholename is a child of dirname, so
    // check for a dir separator.  Special case for dirname == '' (the root),
    // which won't have a slash in position 0.
    if (data->dirname->len > 0 && str->buf[data->dirname->len] != '/') {
        // may have a common prefix with, but is not a child of dirname
        return false;
    }

    if (!data->startswith(str, data->dirname)) {
        return false;
    }

    // Now compute the depth of file from dirname.  We do this by
    // counting dir separators, not including the one we saw above.
    for (i = data->dirname->len + 1; i < str->len; i++) {
        if (str->buf[i] == '/') {
            depth++;
        }
    }

    return eval_int_compare(depth, &data->depth);
}