in shells/abstract.go [160:214]
func (b *AbstractShell) cacheExtractor(w ShellWriter, info common.ShellScriptInfo) error {
for _, cacheOptions := range info.Build.Cache {
// Create list of files to extract
archiverArgs := []string{}
for _, path := range cacheOptions.Paths {
archiverArgs = append(archiverArgs, "--path", path)
}
if cacheOptions.Untracked {
archiverArgs = append(archiverArgs, "--untracked")
}
// Skip restoring cache if no cache is defined
if len(archiverArgs) < 1 {
continue
}
// Skip extraction if no cache is defined
cacheKey, cacheFile := b.cacheFile(info.Build, cacheOptions.Key)
if cacheKey == "" {
continue
}
if ok, err := cacheOptions.CheckPolicy(common.CachePolicyPull); err != nil {
return fmt.Errorf("%s for %s", err, cacheKey)
} else if !ok {
w.Notice("Not downloading cache %s due to policy", cacheKey)
continue
}
args := []string{
"cache-extractor",
"--file", cacheFile,
"--timeout", strconv.Itoa(info.Build.GetCacheRequestTimeout()),
}
// Generate cache download address
if url := getCacheDownloadURL(info.Build, cacheKey); url != nil {
args = append(args, "--url", url.String())
}
// Execute cache-extractor command. Failure is not fatal.
b.guardRunnerCommand(w, info.RunnerCommand, "Extracting cache", func() {
w.Notice("Checking cache for %s...", cacheKey)
w.IfCmdWithOutput(info.RunnerCommand, args...)
w.Notice("Successfully extracted cache")
w.Else()
w.Warning("Failed to extract cache")
w.EndIf()
})
}
return nil
}