Skip to content

Commit

Permalink
cache: fix warning (#1162)
Browse files Browse the repository at this point in the history
Fix warning about not existing cache file.

Fixes: #925
  • Loading branch information
jirfag committed May 24, 2020
1 parent 90a8cd4 commit fd0524f
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions internal/cache/cache.go
Expand Up @@ -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 (
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit fd0524f

Please sign in to comment.