packer/cache: Extract cache path calculation to method

This commit is contained in:
Emil Sit 2013-07-20 00:15:14 -04:00
parent 16d102d055
commit c5fe163352
1 changed files with 6 additions and 2 deletions

View File

@ -44,7 +44,7 @@ func (f *FileCache) Lock(key string) string {
rw := f.rwLock(hashKey)
rw.Lock()
return filepath.Join(f.CacheDir, hashKey)
return f.cachePath(key, hashKey)
}
func (f *FileCache) Unlock(key string) {
@ -58,7 +58,7 @@ func (f *FileCache) RLock(key string) (string, bool) {
rw := f.rwLock(hashKey)
rw.RLock()
return filepath.Join(f.CacheDir, hashKey), true
return f.cachePath(key, hashKey), true
}
func (f *FileCache) RUnlock(key string) {
@ -67,6 +67,10 @@ func (f *FileCache) RUnlock(key string) {
rw.RUnlock()
}
func (f *FileCache) cachePath(key string, hashKey string) string {
return filepath.Join(f.CacheDir, hashKey)
}
func (f *FileCache) hashKey(key string) string {
sha := sha256.New()
sha.Write([]byte(key))