augeas: Return matches list in order
authorRichard W.M. Jones <rjones@redhat.com>
Thu, 8 May 2025 09:04:21 +0000 (10:04 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Thu, 8 May 2025 09:04:21 +0000 (10:04 +0100)
We built the list of matches in reverse order (compared to what Augeas
itself gives us).  So we have to reverse the list after building it so
they are in the normal order.

augeas-c.c
augeas.ml

index 679bcb5..702613a 100644 (file)
@@ -440,7 +440,9 @@ ocaml_augeas_match (value tv, value pathv)
   if (r == -1)
     raise_error (t, "Augeas.matches");
 
-  /* Copy the paths to a list. */
+  /* Copy the paths to a list.
+   * This builds the list in reverse order, but we call List.rev later.
+   */
   rv = Val_int (0);
   for (i = 0; i < r; ++i) {
     v = caml_copy_string (matches[i]);
index aa5a182..8b34641 100644 (file)
--- a/augeas.ml
+++ b/augeas.ml
@@ -76,8 +76,9 @@ external label : t -> path -> string option
   = "ocaml_augeas_label"
 external rm : t -> path -> int
   = "ocaml_augeas_rm"
-external matches : t -> path -> path list
+external matches' : t -> path -> path list
   = "ocaml_augeas_match"
+let matches aug path = List.rev (matches' aug path)
 external count_matches : t -> path -> int
   = "ocaml_augeas_count_matches"
 external save : t -> unit