@@ -181,14 +181,19 @@ func (cmd *UpCmd) Run(cobraCmd *cobra.Command, args []string) {
181181 cmd .pod = pod
182182 }
183183
184- if cmd .flags .sync {
185- cmd .startSync ()
186- }
187-
188184 if cmd .flags .portforwarding {
189185 cmd .startPortForwarding ()
190186 }
191187
188+ if cmd .flags .sync {
189+ syncConfigs := cmd .startSync ()
190+ defer func () {
191+ for _ , v := range syncConfigs {
192+ v .Stop ()
193+ }
194+ }()
195+ }
196+
192197 cmd .enterTerminal ()
193198}
194199
@@ -360,7 +365,9 @@ func (cmd *UpCmd) deployChart() {
360365 log .StopWait ()
361366}
362367
363- func (cmd * UpCmd ) startSync () {
368+ func (cmd * UpCmd ) startSync () []* synctool.SyncConfig {
369+ syncConfigs := make ([]* synctool.SyncConfig , 0 , len (cmd .dsConfig .SyncPaths ))
370+
364371 for _ , syncPath := range cmd .dsConfig .SyncPaths {
365372 absLocalPath , err := filepath .Abs (cmd .workdir + syncPath .LocalSubPath )
366373
@@ -379,7 +386,7 @@ func (cmd *UpCmd) startSync() {
379386 if err != nil {
380387 log .Panicf ("Unable to list devspace pods: %s" , err .Error ())
381388 } else if pod != nil {
382- syncConfig := synctool.SyncConfig {
389+ syncConfig := & synctool.SyncConfig {
383390 Kubectl : cmd .kubectl ,
384391 Pod : pod ,
385392 Container : & pod .Spec .Containers [0 ],
@@ -388,15 +395,17 @@ func (cmd *UpCmd) startSync() {
388395 }
389396
390397 err = syncConfig .Start ()
391-
392398 if err != nil {
393399 log .Fatalf ("Sync error: %s" , err .Error ())
394400 }
395401
396402 log .Donef ("Sync started on %s <-> %s" , absLocalPath , syncPath .ContainerPath )
403+ syncConfigs = append (syncConfigs , syncConfig )
397404 }
398405 }
399406 }
407+
408+ return syncConfigs
400409}
401410
402411func (cmd * UpCmd ) startPortForwarding () {
0 commit comments