MCPcopy
hub / github.com/nektos/act / GetTarArchive

Method GetTarArchive

pkg/runner/local_repository_cache.go:44–100  ·  view source on GitHub ↗
(ctx context.Context, cacheDir, sha, includePrefix string)

Source from the content-addressed store, hash-verified

42}
43
44func (l *LocalRepositoryCache) GetTarArchive(ctx context.Context, cacheDir, sha, includePrefix string) (io.ReadCloser, error) {
45 logger := common.Logger(ctx)
46 // sha is mapped to ref in fetch if there is a local override
47 if dest, ok := l.CacheDirCache[fmt.Sprintf("%s@%s", cacheDir, sha)]; ok {
48 logger.Infof("LocalRepositoryCache read cachedir %s with ref %s and subpath '%s' from %s", cacheDir, sha, includePrefix, dest)
49 srcPath := filepath.Join(dest, includePrefix)
50 buf := &bytes.Buffer{}
51 tw := tar.NewWriter(buf)
52 defer tw.Close()
53 srcPath = filepath.Clean(srcPath)
54 fi, err := os.Lstat(srcPath)
55 if err != nil {
56 return nil, err
57 }
58 tc := &filecollector.TarCollector{
59 TarWriter: tw,
60 }
61 if fi.IsDir() {
62 srcPrefix := srcPath
63 if !strings.HasSuffix(srcPrefix, string(filepath.Separator)) {
64 srcPrefix += string(filepath.Separator)
65 }
66 fc := &filecollector.FileCollector{
67 Fs: &filecollector.DefaultFs{},
68 SrcPath: srcPath,
69 SrcPrefix: srcPrefix,
70 Handler: tc,
71 }
72 err = filepath.Walk(srcPath, fc.CollectFiles(ctx, []string{}))
73 if err != nil {
74 return nil, err
75 }
76 } else {
77 var f io.ReadCloser
78 var linkname string
79 if fi.Mode()&fs.ModeSymlink != 0 {
80 linkname, err = os.Readlink(srcPath)
81 if err != nil {
82 return nil, err
83 }
84 } else {
85 f, err = os.Open(srcPath)
86 if err != nil {
87 return nil, err
88 }
89 defer f.Close()
90 }
91 err := tc.WriteFile(fi.Name(), fi, linkname, f)
92 if err != nil {
93 return nil, err
94 }
95 }
96 return io.NopCloser(buf), nil
97 }
98 logger.Infof("LocalRepositoryCache not matched cachedir %s with Ref %s and subpath '%s'", cacheDir, sha, includePrefix)
99 return l.Parent.GetTarArchive(ctx, cacheDir, sha, includePrefix)
100}

Callers

nothing calls this directly

Calls 11

CollectFilesMethod · 0.95
WriteFileMethod · 0.95
LoggerFunction · 0.92
IsDirMethod · 0.80
ModeMethod · 0.80
NameMethod · 0.80
CloseMethod · 0.65
WalkMethod · 0.65
ReadlinkMethod · 0.65
OpenMethod · 0.65
GetTarArchiveMethod · 0.65

Tested by

no test coverage detected