Archived
1
0

Fill LastModified for Score types

This commit is contained in:
Jip J. Dekker 2016-03-20 23:08:00 +01:00
parent fe24e38627
commit f286816b98
3 changed files with 19 additions and 1 deletions

View File

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

View File

@ -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()

View File

@ -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
}