StartSync starts the syncing functionality
(ctx devspacecontext.Context, devPod *latest.DevPod, selector targetselector.TargetSelector, parent *tomb.Tomb)
| 62 | |
| 63 | // StartSync starts the syncing functionality |
| 64 | func StartSync(ctx devspacecontext.Context, devPod *latest.DevPod, selector targetselector.TargetSelector, parent *tomb.Tomb) (retErr error) { |
| 65 | if ctx == nil || ctx.Config() == nil || ctx.Config().Config() == nil { |
| 66 | return fmt.Errorf("DevSpace config is nil") |
| 67 | } |
| 68 | |
| 69 | // init done array is used to track when sync was initialized |
| 70 | initDoneArray := []chan struct{}{} |
| 71 | loader.EachDevContainer(devPod, func(devContainer *latest.DevContainer) bool { |
| 72 | starter := sync.NewDelayedContainerStarter() |
| 73 | |
| 74 | // make sure we add all the sync paths that need to wait for initial start |
| 75 | for _, syncConfig := range devContainer.Sync { |
| 76 | if syncConfig.StartContainer || (syncConfig.OnUpload != nil && syncConfig.OnUpload.RestartContainer) { |
| 77 | starter.Inc() |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // now start the sync paths |
| 82 | for _, syncConfig := range devContainer.Sync { |
| 83 | // start a new go routine in the tomb |
| 84 | s := syncConfig |
| 85 | syncCtx := ctx |
| 86 | var cancel context.CancelFunc |
| 87 | if s.NoWatch { |
| 88 | var cancelCtx context.Context |
| 89 | cancelCtx, cancel = context.WithCancel(syncCtx.Context()) |
| 90 | syncCtx = syncCtx.WithContext(cancelCtx) |
| 91 | } |
| 92 | initDone := parent.NotifyGo(func() error { |
| 93 | if cancel != nil { |
| 94 | defer cancel() |
| 95 | } |
| 96 | |
| 97 | return startSync(syncCtx, devPod.Name, string(devContainer.Arch), s, selector.WithContainer(devContainer.Container), starter, parent) |
| 98 | }) |
| 99 | initDoneArray = append(initDoneArray, initDone) |
| 100 | |
| 101 | // every five we wait |
| 102 | if len(initDoneArray)%5 == 0 { |
| 103 | for _, initDone := range initDoneArray { |
| 104 | <-initDone |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | return true |
| 109 | }) |
| 110 | |
| 111 | // wait for init chans to be finished |
| 112 | for _, initDone := range initDoneArray { |
| 113 | <-initDone |
| 114 | } |
| 115 | return nil |
| 116 | } |
| 117 | |
| 118 | func startSync(ctx devspacecontext.Context, name, arch string, syncConfig *latest.SyncConfig, selector targetselector.TargetSelector, starter sync.DelayedContainerStarter, parent *tomb.Tomb) error { |
| 119 | // set options |
no test coverage detected