From 39d04c823f11c54e579ed445145545b50a1b591b Mon Sep 17 00:00:00 2001 From: Alexandre Derumier Date: Mon, 6 May 2019 14:47:13 +0200 Subject: [PATCH] write configuration to networks.cfg.new Signed-off-by: Alexandre Derumier --- PVE/Network/Network.pm | 9 +++++---- PVE/Network/Network/Plugin.pm | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/PVE/Network/Network.pm b/PVE/Network/Network.pm index 8bd272f..ee0b973 100644 --- a/PVE/Network/Network.pm +++ b/PVE/Network/Network.pm @@ -27,20 +27,21 @@ sub network_config { } sub config { - - return cfs_read_file("networks.cfg"); + my $config = cfs_read_file("networks.cfg.new"); + $config = cfs_read_file("networks.cfg") if !keys %{$config->{ids}}; + return $config; } sub write_config { my ($cfg) = @_; - cfs_write_file("networks.cfg", $cfg); + cfs_write_file("networks.cfg.new", $cfg); } sub lock_network_config { my ($code, $errmsg) = @_; - cfs_lock_file("networks.cfg", undef, $code); + cfs_lock_file("networks.cfg.new", undef, $code); my $err = $@; if ($err) { $errmsg ? die "$errmsg: $err" : die $err; diff --git a/PVE/Network/Network/Plugin.pm b/PVE/Network/Network/Plugin.pm index e834434..6c34711 100644 --- a/PVE/Network/Network/Plugin.pm +++ b/PVE/Network/Network/Plugin.pm @@ -12,6 +12,9 @@ use PVE::JSONSchema qw(get_standard_option); use base qw(PVE::SectionConfig); PVE::Cluster::cfs_register_file('networks.cfg', + sub { __PACKAGE__->parse_config(@_); }); + +PVE::Cluster::cfs_register_file('networks.cfg.new', sub { __PACKAGE__->parse_config(@_); }, sub { __PACKAGE__->write_config(@_); }); -- 2.39.5