mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-08 22:24:17 +08:00
added mutex lock for conf writes
This commit is contained in:
parent
e88f717bcd
commit
5a3b6141bd
1 changed files with 8 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue