added mutex lock for conf writes

This commit is contained in:
0xdcarns 2022-05-24 13:42:06 -04:00
parent e88f717bcd
commit 5a3b6141bd

View file

@ -10,6 +10,7 @@ import (
"fmt"
"log"
"os"
"sync"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/models"
@ -18,6 +19,10 @@ import (
"gopkg.in/yaml.v3"
)
var (
configLock sync.Mutex
)
// ClientConfig - struct for dealing with client configuration
type ClientConfig struct {
Server ServerConfig `yaml:"server"`
@ -52,6 +57,8 @@ type RegisterResponse struct {
// Write - writes the config of a client to disk
func Write(config *ClientConfig, network string) error {
configLock.Lock()
defer configLock.Unlock()
if network == "" {
err := errors.New("no network provided - exiting")
return err
@ -140,7 +147,7 @@ func ModConfig(node *models.Node) error {
return Write(&modconfig, network)
}
// ModConfig - overwrites the node inside client config on disk
// SaveBackup - saves a backup file of a given network
func SaveBackup(network string) error {
var configPath = ncutils.GetNetclientPathSpecific() + "netconfig-" + network