4
4
"context"
5
5
"sync"
6
6
7
- "github.com/projecteru2/core/cluster"
8
7
"github.com/projecteru2/core/types"
9
8
log "github.com/sirupsen/logrus"
10
9
)
@@ -17,30 +16,20 @@ func (c *Calcium) Copy(ctx context.Context, opts *types.CopyOptions) (chan *type
17
16
wg := sync.WaitGroup {}
18
17
log .Infof ("[Copy] Copy %d workloads files" , len (opts .Targets ))
19
18
// workload one by one
20
- for cid , paths := range opts .Targets {
19
+ for ID , paths := range opts .Targets {
21
20
wg .Add (1 )
22
- go func (cid string , paths []string ) {
21
+ go func (ID string , paths []string ) {
23
22
defer wg .Done ()
24
- workload , err := c .GetWorkload (ctx , cid )
25
- if err != nil {
26
- log .Errorf ("[Copy] Error when get workload %s, err %v" , cid , err )
27
- ch <- makeCopyMessage (cid , cluster .CopyFailed , "" , "" , err , nil )
28
- return
29
- }
30
- for _ , path := range paths {
31
- wg .Add (1 )
32
- go func (path string ) {
33
- defer wg .Done ()
23
+ if err := c .withWorkloadLocked (ctx , ID , func (workload * types.Workload ) error {
24
+ for _ , path := range paths {
34
25
resp , name , err := workload .Engine .VirtualizationCopyFrom (ctx , workload .ID , path )
35
- if err != nil {
36
- log .Errorf ("[Copy] Error during CopyFromWorkload: %v" , err )
37
- ch <- makeCopyMessage (cid , cluster .CopyFailed , "" , path , err , nil )
38
- return
39
- }
40
- ch <- makeCopyMessage (cid , cluster .CopyOK , name , path , nil , resp )
41
- }(path )
26
+ ch <- makeCopyMessage (ID , name , path , err , resp )
27
+ }
28
+ return nil
29
+ }); err != nil {
30
+ ch <- makeCopyMessage (ID , "" , "" , err , nil )
42
31
}
43
- }(cid , paths )
32
+ }(ID , paths )
44
33
}
45
34
wg .Wait ()
46
35
}()
0 commit comments