From ef616ff25b44c10b7148b9dfa2b702d19b791da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 13 Oct 2014 15:12:01 +0200 Subject: [PATCH 1/2] Better handling of wrong config files --- cmd/syncthing/main.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 1c17755ab..bce934b56 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -346,13 +346,20 @@ func syncthingMain() { // Load the configuration file, if it exists. // If it does not, create a template. - cfg, err = config.Load(cfgFile, myID) - if err == nil { - myCfg := cfg.Devices()[myID] - if myCfg.Name == "" { - myName, _ = os.Hostname() + if info, err := os.Stat(cfgFile); err == nil { + if info.IsDir() { + l.Fatalln("config file is a directory!") + } + cfg, err = config.Load(cfgFile, myID) + if err == nil { + myCfg := cfg.Devices()[myID] + if myCfg.Name == "" { + myName, _ = os.Hostname() + } else { + myName = myCfg.Name + } } else { - myName = myCfg.Name + l.Fatalln("Could not load config file, refusing to replace with empty defaults") } } else { l.Infoln("No config file; starting with empty defaults") From 79c3ea82c71ac97bfe4ea308ea313438110ee554 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 13 Oct 2014 15:59:02 +0200 Subject: [PATCH 2/2] More descriptive error if config couldn't be loaded --- cmd/syncthing/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index bce934b56..2e8b3483e 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -347,8 +347,8 @@ func syncthingMain() { // If it does not, create a template. if info, err := os.Stat(cfgFile); err == nil { - if info.IsDir() { - l.Fatalln("config file is a directory!") + if !info.Mode().IsRegular() { + l.Fatalln("Config file is not a file?") } cfg, err = config.Load(cfgFile, myID) if err == nil { @@ -359,7 +359,7 @@ func syncthingMain() { myName = myCfg.Name } } else { - l.Fatalln("Could not load config file, refusing to replace with empty defaults") + l.Fatalln("Configuration:", err) } } else { l.Infoln("No config file; starting with empty defaults")