X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=state.go;h=9b67d9a038d14f3b5e9708c0ffd3e5ca5a9a4895;hb=d946c291618d93e4ab4ad898c1ae317fbe2256e3;hp=b0dec1c2d47673fffa5eb81ee8e3d3113fce689f;hpb=92afde4e875a96e1ab865e29b9f0d11b08d7db1c;p=nsscash%2Fnsscash.git diff --git a/state.go b/state.go index b0dec1c..9b67d9a 100644 --- a/state.go +++ b/state.go @@ -22,15 +22,13 @@ import ( "io/ioutil" "os" "path/filepath" - "reflect" "time" ) type State struct { + // Key is File.Url LastModified map[string]time.Time - - // Copy of LastModified to write the state file only on changes - origLastModified map[string]time.Time + Checksum map[string]string // SHA512 in hex } func LoadState(path string) (*State, error) { @@ -53,20 +51,17 @@ func LoadState(path string) (*State, error) { if state.LastModified == nil { state.LastModified = make(map[string]time.Time) } - - state.origLastModified = make(map[string]time.Time) - for k, v := range state.LastModified { - state.origLastModified[k] = v + if state.Checksum == nil { + state.Checksum = make(map[string]string) } return &state, nil } -func WriteStateIfChanged(path string, state *State) error { - // State hasn't changed, nothing to do - if reflect.DeepEqual(state.LastModified, state.origLastModified) { - return nil - } +func WriteState(path string, state *State) error { + // Update the state file even if nothing has changed to provide a + // simple way to check if nsscash ran successfully (the state is only + // updated if there were no errors) x, err := json.Marshal(state) if err != nil {