From eb412a1084c05930c167a314285c8155b001a080 Mon Sep 17 00:00:00 2001 From: Ilia Rostovtsev Date: Tue, 22 Oct 2019 12:46:30 +0300 Subject: [PATCH] Fix to only order by key config files not other files https://github.com/webmin/webmin/commit/8a81277731d53a4dc29ccd89111bc4a0211e8e66 --- config_save.cgi | 2 +- web-lib-funcs.pl | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/config_save.cgi b/config_save.cgi index 80cb04a8e..e7034dcba 100755 --- a/config_save.cgi +++ b/config_save.cgi @@ -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 diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index 4bfafc484..f06465b18 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -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]};