Skip to content

Commit

Permalink
fix: cached symlinks causing cache misses (#491)
Browse files Browse the repository at this point in the history
Co-authored-by: Jared Palmer <jared@jaredpalmer.com>
  • Loading branch information
adamdottv and jaredpalmer committed Jan 24, 2022
1 parent 52501b6 commit cb4f947
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cli/internal/cache/cache_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func (cache *httpCache) retrieve(key string) (bool, []string, error) {
}
defer resp.Body.Close()
files := []string{}
missingLinks := []*tar.Header{}
if resp.StatusCode == http.StatusNotFound {
return false, files, nil // doesn't exist - not an error
} else if resp.StatusCode != http.StatusOK {
Expand All @@ -132,6 +133,12 @@ func (cache *httpCache) retrieve(key string) (bool, []string, error) {
hdr, err := tr.Next()
if err != nil {
if err == io.EOF {
for _, link := range missingLinks {
if err := os.Symlink(link.Linkname, link.Name); err != nil {
return false, files, err
}
}

return true, files, nil
}
return false, files, err
Expand All @@ -156,6 +163,20 @@ func (cache *httpCache) retrieve(key string) (bool, []string, error) {
return false, files, err
}
case tar.TypeSymlink:
if dir := path.Dir(hdr.Name); dir != "." {
if err := os.MkdirAll(dir, fs.DirPermissions); err != nil {
return false, files, err
}
}
if _, err := os.Lstat(hdr.Name); err == nil {
if err := os.Remove(hdr.Name); err != nil {
return false, files, err
}
} else if os.IsNotExist(err) {
missingLinks = append(missingLinks, hdr)
continue
}

if err := os.Symlink(hdr.Linkname, hdr.Name); err != nil {
return false, files, err
}
Expand Down

1 comment on commit cb4f947

@vercel
Copy link

@vercel vercel bot commented on cb4f947 Jan 24, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.