(dstPath string, srcPath string, useGitIgnore bool)
| 736 | } |
| 737 | |
| 738 | func (cr *containerReference) copyDir(dstPath string, srcPath string, useGitIgnore bool) common.Executor { |
| 739 | return func(ctx context.Context) error { |
| 740 | logger := common.Logger(ctx) |
| 741 | tarFile, err := os.CreateTemp("", "act") |
| 742 | if err != nil { |
| 743 | return err |
| 744 | } |
| 745 | logger.Debugf("Writing tarball %s from %s", tarFile.Name(), srcPath) |
| 746 | defer func(tarFile *os.File) { |
| 747 | name := tarFile.Name() |
| 748 | err := tarFile.Close() |
| 749 | if !errors.Is(err, os.ErrClosed) { |
| 750 | logger.Error(err) |
| 751 | } |
| 752 | err = os.Remove(name) |
| 753 | if err != nil { |
| 754 | logger.Error(err) |
| 755 | } |
| 756 | }(tarFile) |
| 757 | tw := tar.NewWriter(tarFile) |
| 758 | |
| 759 | srcPrefix := filepath.Dir(srcPath) |
| 760 | if !strings.HasSuffix(srcPrefix, string(filepath.Separator)) { |
| 761 | srcPrefix += string(filepath.Separator) |
| 762 | } |
| 763 | logger.Debugf("Stripping prefix:%s src:%s", srcPrefix, srcPath) |
| 764 | |
| 765 | var ignorer gitignore.Matcher |
| 766 | if useGitIgnore { |
| 767 | ps, err := gitignore.ReadPatterns(polyfill.New(osfs.New(srcPath)), nil) |
| 768 | if err != nil { |
| 769 | logger.Debugf("Error loading .gitignore: %v", err) |
| 770 | } |
| 771 | |
| 772 | ignorer = gitignore.NewMatcher(ps) |
| 773 | } |
| 774 | |
| 775 | fc := &filecollector.FileCollector{ |
| 776 | Fs: &filecollector.DefaultFs{}, |
| 777 | Ignorer: ignorer, |
| 778 | SrcPath: srcPath, |
| 779 | SrcPrefix: srcPrefix, |
| 780 | Handler: &filecollector.TarCollector{ |
| 781 | TarWriter: tw, |
| 782 | UID: cr.UID, |
| 783 | GID: cr.GID, |
| 784 | DstDir: dstPath[1:], |
| 785 | }, |
| 786 | } |
| 787 | |
| 788 | err = filepath.Walk(srcPath, fc.CollectFiles(ctx, []string{})) |
| 789 | if err != nil { |
| 790 | return err |
| 791 | } |
| 792 | if err := tw.Close(); err != nil { |
| 793 | return err |
| 794 | } |
| 795 |
no test coverage detected