hercules-team / augeas

A configuration editing tool and API
http://augeas.net/
GNU Lesser General Public License v2.1
486 stars 199 forks source link

Inserting a new comment breaks formatting of following comments #545

Closed mikhirev closed 6 years ago

mikhirev commented 6 years ago

Hello!

I'm using Debian 9 with augeas 1.8.0. When I insert a new comment somewhere in the middle of any configuration file (checked with samba, systemd and ssh lens), e. g. smb.conf, formatting of all the comments below it breaks. #comment[last()] is formatted as the new comment should be, the new #comment[n] is formatted as old #comment[n] (now #comment[n+1]) etc.

% cp /etc/samba/smb.conf /tmp
% augtool --noload --noautoload
augtool> set /augeas/load/Samba/lens Samba.lns
augtool> set /augeas/load/Samba/incl /tmp/smb.conf
augtool> load
augtool> ins #comment after /files/tmp/smb.conf/target[2]/valid\ users
augtool> set /files/tmp/smb.conf/target[2]/#comment[preceding-sibling::*[1][self::valid\ users]] "New comment"
augtool> save
Saved 1 file(s)
augtool> quit 
% diff -du /etc/samba/smb.conf /tmp/smb.conf
--- /etc/samba/smb.conf 2017-11-23 06:11:09.917973027 +0300
+++ /tmp/smb.conf   2018-02-14 15:20:06.041246231 +0300
@@ -206,27 +206,28 @@
 # to \\server\username
 # This might need tweaking when using external authentication schemes
    valid users = %S
+# New comment

 # Un-comment the following and create the netlogon directory for Domain Logons
-# (you need to configure Samba to act as a domain controller too.)
-;[netlogon]
+;(you need to configure Samba to act as a domain controller too.)
+;   [netlogon]
 ;   comment = Network Logon Service
 ;   path = /home/samba/netlogon
 ;   guest ok = yes
-;   read only = yes
+# read only = yes

 # Un-comment the following and create the profiles directory to store
 # users profiles (see the "logon path" option above)
 # (you need to configure Samba to act as a domain controller too.)
 # The path below should be writable by all users so that their
-# profile directory may be created the first time they log on
-;[profiles]
+;profile directory may be created the first time they log on
+;   [profiles]
 ;   comment = Users profiles
 ;   path = /home/samba/profiles
 ;   guest ok = no
 ;   browseable = no
 ;   create mask = 0600
-;   directory mask = 0700
+;directory mask = 0700

 [printers]
    comment = All Printers
%
mikhirev commented 6 years ago

BTW this issue is not limited to comments, but also applies to all indexed nodes.

raphink commented 6 years ago

Thank you for reporting this issue. This is a known bug (dupe of #450)