@@ -597,9 +597,9 @@ func forwardSSH(ctx context.Context, sshConfig *ssh.SSHConfig, port int, local,
597
597
logrus .Infof ("Forwarding %q (host) to %q (guest)" , local , remote )
598
598
} else {
599
599
logrus .Infof ("Forwarding %q (guest) to %q (host)" , remote , local )
600
- }
601
- if err := os . RemoveAll ( local ); err != nil {
602
- logrus . WithError ( err ). Warnf ( "Failed to clean up %q (host) before setting up forwarding" , local )
600
+ if err := os . RemoveAll ( local ); err != nil {
601
+ logrus . WithError ( err ). Warnf ( "Failed to clean up %q (host) before setting up forwarding" , local )
602
+ }
603
603
}
604
604
if err := os .MkdirAll (filepath .Dir (local ), 0750 ); err != nil {
605
605
return fmt .Errorf ("can't create directory for local socket %q: %w" , local , err )
@@ -609,22 +609,24 @@ func forwardSSH(ctx context.Context, sshConfig *ssh.SSHConfig, port int, local,
609
609
logrus .Infof ("Stopping forwarding %q (host) to %q (guest)" , local , remote )
610
610
} else {
611
611
logrus .Infof ("Stopping forwarding %q (guest) to %q (host)" , remote , local )
612
+ defer func () {
613
+ if err := os .RemoveAll (local ); err != nil {
614
+ logrus .WithError (err ).Warnf ("Failed to clean up %q (host) after stopping forwarding" , local )
615
+ }
616
+ }()
612
617
}
613
- defer func () {
614
- if err := os .RemoveAll (local ); err != nil {
615
- logrus .WithError (err ).Warnf ("Failed to clean up %q (host) after stopping forwarding" , local )
616
- }
617
- }()
618
618
default :
619
619
panic (fmt .Errorf ("invalid verb %q" , verb ))
620
620
}
621
621
}
622
622
cmd := exec .CommandContext (ctx , sshConfig .Binary (), args ... )
623
623
if out , err := cmd .Output (); err != nil {
624
624
if verb == verbForward && strings .HasPrefix (local , "/" ) {
625
- logrus .WithError (err ).Warnf ("Failed to set up forward from %q (guest) to %q (host)" , remote , local )
626
- if removeErr := os .RemoveAll (local ); err != nil {
627
- logrus .WithError (removeErr ).Warnf ("Failed to clean up %q (host) after forwarding failed" , local )
625
+ if ! reverse {
626
+ logrus .WithError (err ).Warnf ("Failed to set up forward from %q (guest) to %q (host)" , remote , local )
627
+ if removeErr := os .RemoveAll (local ); err != nil {
628
+ logrus .WithError (removeErr ).Warnf ("Failed to clean up %q (host) after forwarding failed" , local )
629
+ }
628
630
}
629
631
}
630
632
return fmt .Errorf ("failed to run %v: %q: %w" , cmd .Args , string (out ), err )
0 commit comments