(ctx context.Context, projectName string, options api.CopyOptions)
| 49 | } |
| 50 | |
| 51 | func (s *composeService) copy(ctx context.Context, projectName string, options api.CopyOptions) error { |
| 52 | projectName = strings.ToLower(projectName) |
| 53 | srcService, srcPath := splitCpArg(options.Source) |
| 54 | destService, dstPath := splitCpArg(options.Destination) |
| 55 | |
| 56 | var direction copyDirection |
| 57 | var serviceName string |
| 58 | var copyFunc func(ctx context.Context, containerID string, srcPath string, dstPath string, opts api.CopyOptions) error |
| 59 | if srcService != "" { |
| 60 | direction |= fromService |
| 61 | serviceName = srcService |
| 62 | copyFunc = s.copyFromContainer |
| 63 | } |
| 64 | if destService != "" { |
| 65 | direction |= toService |
| 66 | serviceName = destService |
| 67 | copyFunc = s.copyToContainer |
| 68 | } |
| 69 | if direction == acrossServices { |
| 70 | return errors.New("copying between services is not supported") |
| 71 | } |
| 72 | |
| 73 | if direction == 0 { |
| 74 | return errors.New("unknown copy direction") |
| 75 | } |
| 76 | |
| 77 | containers, err := s.listContainersTargetedForCopy(ctx, projectName, options, direction, serviceName) |
| 78 | if err != nil { |
| 79 | return err |
| 80 | } |
| 81 | |
| 82 | g := errgroup.Group{} |
| 83 | for _, cont := range containers { |
| 84 | ctr := cont |
| 85 | g.Go(func() error { |
| 86 | name := getCanonicalContainerName(ctr) |
| 87 | var msg string |
| 88 | if direction == fromService { |
| 89 | msg = fmt.Sprintf("%s:%s to %s", name, srcPath, dstPath) |
| 90 | } else { |
| 91 | msg = fmt.Sprintf("%s to %s:%s", srcPath, name, dstPath) |
| 92 | } |
| 93 | s.events.On(api.Resource{ |
| 94 | ID: name, |
| 95 | Text: api.StatusCopying, |
| 96 | Details: msg, |
| 97 | Status: api.Working, |
| 98 | }) |
| 99 | if err := copyFunc(ctx, ctr.ID, srcPath, dstPath, options); err != nil { |
| 100 | return err |
| 101 | } |
| 102 | s.events.On(api.Resource{ |
| 103 | ID: name, |
| 104 | Text: api.StatusCopied, |
| 105 | Details: msg, |
| 106 | Status: api.Done, |
| 107 | }) |
| 108 | return nil |
no test coverage detected