MCPcopy Index your code
hub / github.com/devspace-sh/devspace / StartSync

Function StartSync

pkg/devspace/services/sync/sync.go:64–116  ·  view source on GitHub ↗

StartSync starts the syncing functionality

(ctx devspacecontext.Context, devPod *latest.DevPod, selector targetselector.TargetSelector, parent *tomb.Tomb)

Source from the content-addressed store, hash-verified

62
63// StartSync starts the syncing functionality
64func 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
118func startSync(ctx devspacecontext.Context, name, arch string, syncConfig *latest.SyncConfig, selector targetselector.TargetSelector, starter sync.DelayedContainerStarter, parent *tomb.Tomb) error {
119 // set options

Callers 1

startServicesMethod · 0.92

Calls 10

IncMethod · 0.95
EachDevContainerFunction · 0.92
startSyncFunction · 0.85
NotifyGoMethod · 0.80
ConfigMethod · 0.65
ContextMethod · 0.65
WithContextMethod · 0.65
WithContainerMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected