On Sat, 2010-10-16 at 10:36 -0400, Francis Giraldeau wrote: 
> I would propose the attached patch to add this capability to the API. I
> find that it could be useful also for sanity check in other
> applications, like in a GUI, when a duplicated model must stay in sync
> with the augeas tree. 

I like this idea, though would prefer a less generic name, e.g.
'aug_node_count'

Also, the implementation of aug_size has a problem:

> +int aug_size(const struct augeas *aug, const char *path) {
> +    struct pathx *p;
> +    struct tree *root;
> +    int r = 0;
> +
> +    api_entry(aug);
> +
> +    if (path == NULL || strlen(path) == 0) {
> +        path = "/*";
> +    }
> +
> +    p = pathx_aug_parse(aug, aug->origin, path, true);
> +    ERR_BAIL(aug);
> +    pathx_find_one(p, &root);
> +
> +    if (root != NULL)
> +        r = tree_size(root);

pathx_find_one will return one node, even if the path expression matches
many nodes (e.g., '/augeas//error')

You need to iterate over all matches, similar to what aug_match does:

  int result = 0;
  for (root = pathx_first(p); root != NULL; root = pathx_next(p)) {
    result += tree_size(root);
  }

David


_______________________________________________
augeas-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/augeas-devel

Reply via email to