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

Add Aptsources822 lens for Deb822 style Apt sources #801

Open jvalleroy opened 1 year ago

jvalleroy commented 1 year ago

We are using this lens in FreedomBox to add/remove "tor+" prefix to Apt sources URIs. Original commit: https://salsa.debian.org/freedombox-team/freedombox/-/commit/cd21c7f247135828e63379cc6d32a8edcb53a582

Closes: #297.

Signed-off-by: James Valleroy jvalleroy@mailbox.org

georgehansper commented 1 year ago

The lenses aptsources.aug and aptsources822.aug have overlapping definitions in the filter statement. This results in an error because augeas can't determine which of the two lenses to apply. eg.

Error in /etc/apt/sources.list.d/man_examples.sources (mxfm_load) Lenses @Aptsources822 and @Aptsources could be used to load this file

According to the man page for sources.list.d:

Filenames need to have either the extension .list or .sources depending on the contained format

This means that the existing lens should be limited to files named *.list, like this:

diff --git a/lenses/aptsources.aug b/lenses/aptsources.aug
index d7a6b3b1..e09634c7 100644
--- a/lenses/aptsources.aug
+++ b/lenses/aptsources.aug
@@ -60,7 +60,7 @@ module Aptsources =

   (* View: filter *)
   let filter = (incl "/etc/apt/sources.list")
-      . (incl "/etc/apt/sources.list.d/*")
+      . (incl "/etc/apt/sources.list.d/*.list")
       . Util.stdexcl

   let xfm = transform lns filter

Although this could be the subject of a separate PR, can I ask you to update this PR with the above change?

georgehansper commented 1 year ago

The lens works well, and thank you in particular for including tests

Just one point, if I may: Each "paragraph" must be separated by a non-comment blank line This is handled correctly by this lens.

Multiple blank lines are permitted between "paragraphs", as long as there is at least one blank line Zero or more leading and trailing blank lines are permitted Currently, extraneous blank lines like this are not handled by this lens

Could you please update the lens to allow leading, trailing and repeated blank lines?