cache: fix warning (#1162)

Fix warning about not existing cache file.

Fixes: #925
This commit is contained in:
Denis Isaev 2020-05-24 10:19:00 +03:00 committed by GitHub
parent 90a8cd41bd
commit fd0524f535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,7 +81,7 @@ func (c *Cache) fileName(id [HashSize]byte, key string) string {
var errMissing = errors.New("cache entry not found")
func IsErrMissing(err error) bool {
return err == errMissing
return errors.Cause(err) == errMissing
}
const (
@ -199,26 +199,6 @@ func (c *Cache) get(id ActionID) (Entry, error) {
return Entry{buf, size, time.Unix(0, tm)}, nil
}
// GetFile looks up the action ID in the cache and returns
// the name of the corresponding data file.
func (c *Cache) GetFile(id ActionID) (file string, entry Entry, err error) {
entry, err = c.Get(id)
if err != nil {
return "", Entry{}, err
}
file, err = c.OutputFile(entry.OutputID)
if err != nil {
return "", Entry{}, err
}
info, err := os.Stat(file)
if err != nil || info.Size() != entry.Size {
return "", Entry{}, errMissing
}
return file, entry, nil
}
// GetBytes looks up the action ID in the cache and returns
// the corresponding output bytes.
// GetBytes should only be used for data that can be expected to fit in memory.
@ -282,6 +262,9 @@ const (
func (c *Cache) used(file string) error {
info, err := os.Stat(file)
if err != nil {
if os.IsNotExist(err) {
return errMissing
}
return errors.Wrapf(err, "failed to stat file %s", file)
}