这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: cached symlinks causing cache misses #491

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

Merged
merged 4 commits into from
Jan 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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