Skip to content

Commit

Permalink
Set timeout on cached hashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
sselph committed Oct 23, 2014
1 parent a5777f0 commit 236afa1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ func exists(s string) bool {
return !os.IsNotExist(err) && fi.Size() > 0
}

func validTemp(s string) bool {
fi, err := os.Stat(s)
if err != nil || fi.Size() == 0 {
return false
}
n := time.Now()
t := fi.ModTime().Add(30 * time.Minute)
if t.Before(n) {
return false
}
return true
}

// worker is a function to process roms from a channel.
func worker(hm map[string]string, results chan GameXML, roms chan string, wg *sync.WaitGroup) {
defer wg.Done()
Expand Down Expand Up @@ -348,7 +361,7 @@ func GetHashMap() (map[string]string, error) {
if err != nil {
return ret, err
}
case exists(tempFile):
case validTemp(tempFile):
f, err = os.Open(tempFile)
if err != nil {
return ret, err
Expand Down

0 comments on commit 236afa1

Please sign in to comment.