"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) {
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 {