summaryrefslogtreecommitdiffstats
path: root/perl-install/network
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.org>2004-08-24 13:31:07 +0000
committerOlivier Blin <oblin@mandriva.org>2004-08-24 13:31:07 +0000
commit7c618bc6b5a11cf92edba042ef872eafe619dd8d (patch)
tree618a7de91288b767e025c09c6280fea4f0d5be8b /perl-install/network
parentf93452c4ca9ac841a41c152f013c8fb960826f06 (diff)
downloaddrakx-backup-do-not-use-7c618bc6b5a11cf92edba042ef872eafe619dd8d.tar
drakx-backup-do-not-use-7c618bc6b5a11cf92edba042ef872eafe619dd8d.tar.gz
drakx-backup-do-not-use-7c618bc6b5a11cf92edba042ef872eafe619dd8d.tar.bz2
drakx-backup-do-not-use-7c618bc6b5a11cf92edba042ef872eafe619dd8d.tar.xz
drakx-backup-do-not-use-7c618bc6b5a11cf92edba042ef872eafe619dd8d.zip
(add2hosts) rework parsing
Diffstat (limited to 'perl-install/network')
-rw-r--r--perl-install/network/network.pm15
1 files changed, 10 insertions, 5 deletions
diff --git a/perl-install/network/network.pm b/perl-install/network/network.pm
index 1bd0a2c72..473535ae8 100644
--- a/perl-install/network/network.pm
+++ b/perl-install/network/network.pm
@@ -171,11 +171,16 @@ sub write_interface_conf {
sub add2hosts {
my ($file, $hostname, @ips) = @_;
- my $sub_hostname = $hostname =~ /(.*?)\./ ? " $1" : '';
- my %l = map { if_(/^\s*(\S+)(.*)/, $1 => $2) }
- grep { !/\s\Q$hostname$sub_hostname\E(\s|$)/ } cat_($file);
-
- $l{$_} .= ($l{$_} ? " " : "\t\t") . "$hostname$sub_hostname" foreach grep { $_ } @ips;
+ my ($sub_hostname) = $hostname =~ /(.*?)\./;
+ my %l = map {
+ my ($ip, $space, $aliases) = /^\s*(\S+)(\s+)(\S+.*)/;
+ $aliases =~ s/(^|\s+)\Q$hostname\E(\s+|$)/$1/g;
+ $sub_hostname and $aliases =~ s/(^|\s+)\Q$sub_hostname\E(\s+|$)/$1/g;
+ if_($aliases !~ /^\s*$/, $ip => $space . $aliases)
+ } cat_($file);
+
+ $sub_hostname and $hostname = "$hostname $sub_hostname";
+ $l{$_} .= ($l{$_} ? " " : "\t\t") . $hostname foreach grep { $_ } @ips;
log::explanations("writing host information to $file");
output($file, map { "$_$l{$_}\n" } keys %l);