<div dir="ltr"><div><div><div>Hi Josef,<br><br></div>that is indeed an icky problem. There is currently no direct way to get the newly inserted node. Besides carefully recomputing indices like you described, the only other way I can think of is to use the following-sibling and preceding-sibling axes in path expressions. For example, to get the comment right before the first real entry in /etc/hosts you'd do<br><br><div style="margin-left:40px">match /files/etc/hosts/#comment[following-sibling::1][last()]<br><br></div>This is based on the fact that the first real entry in /etc/hosts is /files/etc/hosts/1 (i.e., the '1' in the above path expression is the label of a node). /files/etc/hosts/#comment matches all comments in /etc/hosts, [following-sibling::1] restricts that to all the comments that come before /files/etc/hosts/1, and the [last()] picks out the last of those comments.<br><br></div>Similarly, you'd pick the comment right after /files/etc/hosts/1 with<br><br><div style="margin-left:40px">match /files/etc/hosts/#comment[preceding-sibling::1][1]<br><br></div>I'd agree though that writing these path expressions isn't anybody's idea of fun. Another approach would be to change some commands to set a variable (say $_last) to point to the newly inserted node, so that you could just do 'match $_last' to get the inserted node. There's probably more commands that could benefit from that, particularly set. What do you think ?<br><br></div>David<br><div><div><div><div><div><div><br></div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 14, 2017 at 3:12 AM, Josef Reidinger <span dir="ltr"><<a href="mailto:jreidinger@suse.com" target="_blank">jreidinger@suse.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Good morning to list,<br>
Let me at first get context. I am using augeas ruby bindings to do some<br>
automatic changes in configuration files. I build some tools around<br>
allowing easier access to augeas, but I have now one challenge.<br>
<br>
In general I have set of modifications, additional entries and removed<br>
entries. My challenge is that path is not stable, so when new entry is<br>
added or removed from array like #comment, then it changes path of<br>
other items in array.<br>
<br>
So consider this scenario. I need to modify two comments, remove two<br>
comments and add comment before another comment. The first part is<br>
easy and I use set. The second part I already solved as I know original<br>
path and do it in reverse order so e.g. remove #comment[50] and<br>
#comment[36]. Then I want to add new #comment before original<br>
#comment[10] but it is no longer #comment[10] and I also do not know<br>
what will be number of new comment ( ok, in this case I know it is path<br>
of comment I inserted before, but sometimes I need to add it before<br>
another key like "inst #comment before $prefix/alias[5]" then is there<br>
easy way how to get path of newly inserted label? like<br>
$prefix/#comment[16] ?<br>
<br>
Also is there way how to get what is old path? Value is not unique,<br>
especially in comments and I find manually counting and changing all<br>
indexes quite complex.<br>
<br>
Thanks for help and tips.<br>
<br>
Josef<br>
<br>
______________________________<wbr>_________________<br>
augeas-devel mailing list<br>
<a href="mailto:augeas-devel@redhat.com">augeas-devel@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/augeas-devel" rel="noreferrer" target="_blank">https://www.redhat.com/<wbr>mailman/listinfo/augeas-devel</a><br>
</blockquote></div><br></div>