Skip to content

Commit

Permalink
try to load stat.bak if stat is invalid, or start new one is both are
Browse files Browse the repository at this point in the history
invalid
fixes cyfdecyf#309
  • Loading branch information
fzerorubigd authored and cyfdecyf committed May 10, 2015
1 parent d898284 commit c87cbb2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions sitestat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit c87cbb2

Please sign in to comment.