[type/__mail_alias] Some fixes in continuation line processing
This commit is contained in:
parent
27102340de
commit
c777a2b1c2
2 changed files with 27 additions and 23 deletions
|
@ -17,13 +17,15 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Find aliases for a given name and print the aliases line separated
|
||||
# Find aliases for a given user name and print the aliases (each one on a
|
||||
# separate line)
|
||||
|
||||
aliases_file=$("${__type_explorer}/aliases_file")
|
||||
test -r "${aliases_file}" || exit 0
|
||||
|
||||
awk -F ':[ \t]*' '
|
||||
function print_aliases(aliases, matches) {
|
||||
# prints comma-separated aliases (one per line)
|
||||
split(aliases, matches, /,[ \t]*/)
|
||||
for (i in matches) {
|
||||
gsub(/^[ \t]*|[ \t]*$/, "", matches[i])
|
||||
|
@ -37,15 +39,11 @@ function print_aliases(aliases, matches) {
|
|||
next
|
||||
}
|
||||
|
||||
/^[ \t]/ || cont {
|
||||
# continuation line (either the previous line ended in a backslash or the
|
||||
# line starts with whitespace)
|
||||
|
||||
if (select)
|
||||
print_aliases($0)
|
||||
}
|
||||
|
||||
{
|
||||
# is this line a continuation line?
|
||||
# (the prev. line ended in a backslash or the line starts with whitespace)
|
||||
is_cont = /^[ \t]/ || cont
|
||||
|
||||
# detect if the line is a line to be continued (ends with a backslash)
|
||||
cont = ($0 ~ /\\$/)
|
||||
|
||||
|
@ -57,9 +55,14 @@ function print_aliases(aliases, matches) {
|
|||
}
|
||||
}
|
||||
|
||||
$1 == ENVIRON["__object_id"] && !select {
|
||||
is_cont {
|
||||
# if in the alias list of the "target" user, we also print these aliases.
|
||||
if (select) print_aliases($0)
|
||||
next
|
||||
}
|
||||
|
||||
$1 == ENVIRON["__object_id"] {
|
||||
# "target" user -> print alias list
|
||||
# (only if !select; because of whitespacecontinuation lines)
|
||||
select = 1
|
||||
print_aliases($2)
|
||||
next
|
||||
|
|
|
@ -91,29 +91,30 @@ BEGIN {
|
|||
aliases_should_file = (ENVIRON["__object"] "/parameter/alias")
|
||||
}
|
||||
|
||||
/^#/ {
|
||||
/^[ \t]*\#/ {
|
||||
# comment line (leave alone)
|
||||
select = 0; cont = 0 # comments terminate alias lists and continuations
|
||||
print
|
||||
next
|
||||
}
|
||||
|
||||
/^[ \t]/ || cont {
|
||||
# continuation line (either the previous line ended in a backslash or the
|
||||
# line starts with whitespace)
|
||||
|
||||
# if in the alias list of the "target" user, we drop the line as it has been
|
||||
# rewritten previously
|
||||
if (select) next
|
||||
}
|
||||
|
||||
{
|
||||
# is this line a continuation line?
|
||||
# (the prev. line ended in a backslash or the line starts with whitespace)
|
||||
is_cont = /^[ \t]/ || cont
|
||||
|
||||
# detect if the line is a line to be continued (ends with a backslash)
|
||||
cont = ($0 ~ /\\$/)
|
||||
# if it is, we drop the backslash from the line.
|
||||
if (cont) sub(/[ \t]*\\$/, "", $0)
|
||||
}
|
||||
|
||||
is_cont {
|
||||
# we ignore the line as it has been rewritten previously or is not
|
||||
# interesting
|
||||
next
|
||||
}
|
||||
|
||||
$1 == ENVIRON["__object_id"] {
|
||||
# "target" user -> rewrite aliases list
|
||||
select = 1
|
||||
|
@ -139,7 +140,7 @@ END {
|
|||
|
||||
if ! cmp -s "${aliases_file}" "${aliases_file}.tmp"
|
||||
then
|
||||
# aliases file was modified, replace and run `newaliases`
|
||||
# aliases file was modified, replace and run `newaliases`.
|
||||
mv "${aliases_file}.tmp" "${aliases_file}"
|
||||
newaliases
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue