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

Method CopyTarStream

pkg/container/docker_run.go:709–736  ·  view source on GitHub ↗
(ctx context.Context, destPath string, tarStream io.Reader)

Source from the content-addressed store, hash-verified

707}
708
709func (cr *containerReference) CopyTarStream(ctx context.Context, destPath string, tarStream io.Reader) error {
710 if common.Dryrun(ctx) {
711 return nil
712 }
713 // Mkdir
714 buf := &bytes.Buffer{}
715 tw := tar.NewWriter(buf)
716 _ = tw.WriteHeader(&tar.Header{
717 Name: destPath,
718 Mode: 0o777,
719 Typeflag: tar.TypeDir,
720 })
721 tw.Close()
722 _, err := cr.cli.CopyToContainer(ctx, cr.id, client.CopyToContainerOptions{DestinationPath: "/", Content: buf})
723 if err != nil {
724 return fmt.Errorf("failed to mkdir to copy content to container: %w", err)
725 }
726 // Copy Content
727 _, err = cr.cli.CopyToContainer(ctx, cr.id, client.CopyToContainerOptions{DestinationPath: destPath, Content: tarStream})
728 if err != nil {
729 return fmt.Errorf("failed to copy content to container: %w", err)
730 }
731 // If this fails, then folders have wrong permissions on non root container
732 if cr.UID != 0 || cr.GID != 0 {
733 _ = cr.Exec([]string{"chown", "-R", fmt.Sprintf("%d:%d", cr.UID, cr.GID), destPath}, nil, "0", "")(ctx)
734 }
735 return nil
736}
737
738func (cr *containerReference) copyDir(dstPath string, srcPath string, useGitIgnore bool) common.Executor {
739 return func(ctx context.Context) error {

Calls 4

ExecMethod · 0.95
DryrunFunction · 0.92
CopyToContainerMethod · 0.80
CloseMethod · 0.65