mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-10 15:14:22 +08:00
adding backup function
This commit is contained in:
parent
8eef12036d
commit
2865089ff0
1 changed files with 26 additions and 12 deletions
|
@ -95,28 +95,42 @@ func (config *ClientConfig) ConfigFileExists() bool {
|
||||||
// ClientConfig.ReadConfig - used to read config from client disk into memory
|
// ClientConfig.ReadConfig - used to read config from client disk into memory
|
||||||
func (config *ClientConfig) ReadConfig() {
|
func (config *ClientConfig) ReadConfig() {
|
||||||
|
|
||||||
nofile := false
|
network := config.Network
|
||||||
|
if network == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//home, err := homedir.Dir()
|
//home, err := homedir.Dir()
|
||||||
home := ncutils.GetNetclientPathSpecific()
|
home := ncutils.GetNetclientPathSpecific()
|
||||||
|
|
||||||
file := fmt.Sprintf(home + "netconfig-" + config.Network)
|
file := fmt.Sprintf(home + "netconfig-" + network)
|
||||||
//f, err := os.Open(file)
|
//f, err := os.Open(file)
|
||||||
f, err := os.OpenFile(file, os.O_RDONLY, 0600)
|
f, err := os.OpenFile(file, os.O_RDONLY, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Log(1, "trouble opening file: ", err.Error())
|
logger.Log(1, "trouble opening file: ", err.Error())
|
||||||
nofile = true
|
if err = ReplaceWithBackup(network); err != nil {
|
||||||
//fmt.Println("Could not access " + home + "/.netconfig, proceeding...")
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
f, err = os.Open(file)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
if err := yaml.NewDecoder(f).Decode(&config); err != nil {
|
||||||
//var cfg ClientConfig
|
logger.Log(0, "no config or invalid, replacing with backup")
|
||||||
|
if err = ReplaceWithBackup(network); err != nil {
|
||||||
if !nofile {
|
log.Fatal(err)
|
||||||
decoder := yaml.NewDecoder(f)
|
}
|
||||||
err = decoder.Decode(&config)
|
f.Close()
|
||||||
|
f, err = os.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("no config or invalid")
|
log.Fatal(err)
|
||||||
fmt.Println(err)
|
}
|
||||||
|
defer f.Close()
|
||||||
|
if err := yaml.NewDecoder(f).Decode(&config); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue