From c87cbb215e14e1d8a99f0dd1bf47bea9b19f1fc4 Mon Sep 17 00:00:00 2001 From: fzerorubigd Date: Sat, 9 May 2015 20:14:10 +0430 Subject: [PATCH] try to load stat.bak if stat is invalid, or start new one is both are invalid fixes #309 --- sitestat.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sitestat.go b/sitestat.go index e5c0ceb1..02097802 100644 --- a/sitestat.go +++ b/sitestat.go @@ -4,13 +4,14 @@ import ( "encoding/json" "errors" "fmt" - "github.com/cyfdecyf/bufio" "io/ioutil" "math/rand" "os" "strings" "sync" "time" + + "github.com/cyfdecyf/bufio" ) func init() { @@ -426,9 +427,18 @@ func (ss *SiteStat) GetDirectList() []string { var siteStat = newSiteStat() func initSiteStat() { - if err := siteStat.load(configPath.stat); err != nil { - os.Exit(1) + err := siteStat.load(configPath.stat) + if err != nil { + errl.Printf("loading stat file failed, reason : %s", err.Error()) + // Simply try to load the stat.back + err = siteStat.load(configPath.stat + ".bak") + // After all its not critical , simply re-create a stat object if anything is not ok + if err != nil { + errl.Printf("loading stat backup failed, creating new one , reason: %s", err.Error()) + siteStat = newSiteStat() + } } + // Dump site stat while running, so we don't always need to close cow to // get updated stat. go func() {