Fix to only order by key config files not other files 8a81277731

This commit is contained in:
Ilia Rostovtsev
2019-10-22 12:46:30 +03:00
parent 6701e9f756
commit eb412a1084
2 changed files with 21 additions and 10 deletions

View File

@@ -34,7 +34,7 @@ if (!$func) {
# Use config.info to parse config inputs
&parse_config(\%newconfig, "$mdir/config.info", $m);
}
&write_file("$config_directory/$m/config", \%newconfig);
&write_file("$config_directory/$m/config", \%newconfig, undef, 1);
&unlock_file("$config_directory/$m/config");
# Call any post-config save function

View File

@@ -127,7 +127,7 @@ $main::read_file_cache_time{$realfile} = $st[9];
return $rv;
}
=head2 write_file(file, &hash, [join-char])
=head2 write_file(file, &hash, [join-char], [sort])
Write out the contents of a hash as name=value lines. The parameters are :
@@ -137,6 +137,8 @@ Write out the contents of a hash as name=value lines. The parameters are :
=item join-char - If given, names and values are separated by this instead of =
=item sort - If given, passed hash reference will be sorted by its keys
=cut
sub write_file
{
@@ -145,18 +147,27 @@ my $join = defined($_[2]) ? $_[2] : "=";
my $realfile = &translate_filename($_[0]);
&read_file($_[0], \%old, \@order);
&open_tempfile(ARFILE, ">$_[0]");
foreach $k (sort @order) {
if (exists($_[1]->{$k})) {
if ($_[3]) {
foreach $k (sort keys %{$_[1]}) {
(print ARFILE $k,$join,$_[1]->{$k},"\n") ||
&error(&text("efilewrite", $realfile, $!));
}
}
}
foreach $k (sort keys %{$_[1]}) {
if (!exists($old{$k})) {
(print ARFILE $k,$join,$_[1]->{$k},"\n") ||
&error(&text("efilewrite", $realfile, $!));
else {
foreach $k (@order) {
if (exists($_[1]->{$k})) {
(print ARFILE $k,$join,$_[1]->{$k},"\n") ||
&error(&text("efilewrite", $realfile, $!));
}
}
}
foreach $k (keys %{$_[1]}) {
if (!exists($old{$k})) {
(print ARFILE $k,$join,$_[1]->{$k},"\n") ||
&error(&text("efilewrite", $realfile, $!));
}
}
}
&close_tempfile(ARFILE);
if (defined($main::read_file_cache{$realfile})) {
%{$main::read_file_cache{$realfile}} = %{$_[1]};