github.com/ernestokarim/closurer@v0.0.0-20130119214741-f245d086c750/cache/modification.go (about)

     1  package cache
     2  
     3  import (
     4  	"os"
     5  	"time"
     6  
     7  	"github.com/ernestokarim/closurer/app"
     8  	"github.com/ernestokarim/closurer/config"
     9  )
    10  
    11  var modificationCache = map[string]time.Time{}
    12  
    13  // Checks if filename has been modified since the last time
    14  // it was scanned. It so, or if it's not present in the cache,
    15  // it returns true and stores the new time.
    16  func Modified(dest, filename string) (bool, error) {
    17  	if config.NoCache {
    18  		return true, nil
    19  	}
    20  
    21  	name := dest + filename
    22  
    23  	info, err := os.Lstat(filename)
    24  	if err != nil {
    25  		return false, app.Error(err)
    26  	}
    27  
    28  	modified, ok := modificationCache[name]
    29  
    30  	if !ok || info.ModTime() != modified {
    31  		modificationCache[name] = info.ModTime()
    32  		return true, nil
    33  	}
    34  
    35  	return false, nil
    36  }