in command-runner/pkg/runner/shell_command_executor.go [186:215]
func copyDir(ctx context.Context, destdir string, sourcedir string, useGitIgnore bool) error {
if sourcedir == destdir {
return fmt.Errorf("unable to copyDir when sourcedir==destdir")
}
log.Ctx(ctx).Debug().Msgf("Copying from %s to %s", sourcedir, destdir)
srcPrefix := filepath.Dir(sourcedir)
if !strings.HasSuffix(srcPrefix, string(filepath.Separator)) {
srcPrefix += string(filepath.Separator)
}
log.Ctx(ctx).Debug().Msgf("Stripping prefix:%s src:%s", srcPrefix, sourcedir)
var ignorer gitignore.Matcher
if useGitIgnore {
ps, err := gitignore.ReadPatterns(polyfill.New(osfs.New(sourcedir)), nil)
if err != nil {
log.Ctx(ctx).Debug().Msgf("Error loading .gitignore: %v", err)
}
ignorer = gitignore.NewMatcher(ps)
}
fc := &fs.FileCollector{
Fs: &fs.DefaultFs{},
Ignorer: ignorer,
SrcPath: sourcedir,
SrcPrefix: srcPrefix,
Handler: &fs.CopyCollector{
DstDir: destdir,
},
}
return filepath.Walk(sourcedir, fc.CollectFiles(ctx, []string{}))
}