Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache: fix warning #1162

Merged
merged 1 commit into from May 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, you are right. We will fix when will be replacing pkg/errors by errors. I guess it can happen with go1.15.

}

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