From f286816b980cbc8f080583d11b8b3db29d938ebb Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Sun, 20 Mar 2016 23:08:00 +0100 Subject: [PATCH] Fill LastModified for Score types --- compiler/compile.go | 5 ++++- helpers/file_utils.go | 11 +++++++++++ settings/score.go | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/compiler/compile.go b/compiler/compile.go index f75d89f..2a667ba 100644 --- a/compiler/compile.go +++ b/compiler/compile.go @@ -52,7 +52,10 @@ func generateScores() func(string, os.FileInfo) error { switch filepath.Ext(path) { case ".ly": log.WithFields(log.Fields{"path": path}).Info("adding lilypond file") - scores = append(scores, &settings.Score{Path: path}) + scores = append(scores, &settings.Score{ + Path: path, + LastModified: file.LastModified, + }) case ".json": if filepath.Base(path) != "ponder.json" { diff --git a/helpers/file_utils.go b/helpers/file_utils.go index 1cda761..2054573 100644 --- a/helpers/file_utils.go +++ b/helpers/file_utils.go @@ -18,6 +18,7 @@ import ( "errors" "os" "path/filepath" + "time" log "github.com/Sirupsen/logrus" ) @@ -54,6 +55,16 @@ func Exists(path string) bool { return false } +// LastModified returns the time the file on the path was last modified, +// if file lookup fails the current time is returned. +func LastModified(path string) time.Time { + stat, err := os.Stat(path) + if err == nil { + return stat.LastModified + } + return time.Now() +} + // FindFileDir returns the path of the func FindFileDir(file string) (string, error) { wd, err := os.Getwd() diff --git a/settings/score.go b/settings/score.go index 39349c1..0e676be 100644 --- a/settings/score.go +++ b/settings/score.go @@ -18,6 +18,8 @@ import ( "encoding/json" "io/ioutil" "time" + + "github.com/jjdekker/ponder/helpers" ) // Score represents the settings for a specific score file @@ -40,5 +42,7 @@ func FromJSON(path string) (*Score, error) { if err != nil { return nil, err } + s.LastModified = helpers.LastModified(s.Path) + return &s, nil }