package hash import ( "encoding/json" "io/ioutil" "path/filepath" "time" ) // Fdhashes struct for holding all informations about one folder. type Fdhashes struct { Path string Hashes map[string]string Times map[string]time.Time Dirty bool } func LoadHashfile(fileStr string) (*Fdhashes, error) { dir, _ := filepath.Split(fileStr) dir = filepath.ToSlash(filepath.Clean(dir)) var data Fdhashes file, err := ioutil.ReadFile(fileStr) if err != nil { return nil, err } err = json.Unmarshal([]byte(file), &data) if err != nil { return nil, err } if data.Path != dir { data.Path = dir data.Dirty = true } return &data, nil } /* func LoadHashfile(fileStr string) Fdhashes { dir, _ := filepath.Split(fileStr) dir = filepath.ToSlash(filepath.Clean(dir)) data := Fdhashes{Path: dir, Hashes: make(map[string]string), Times: make(map[string]time.Time), Dirty: false} if !rewrite { file, err := ioutil.ReadFile(fileStr) if err != nil { panic(err) } err = json.Unmarshal([]byte(file), &data) if err != nil { log.Printf("can't read file %s", fileStr) } } if data.Path != dir { data.Path = dir data.Dirty = true } return data } */