Skip to content

Commit 9ad821b

Browse files
committed
pkg/hostagent: Remove ControlMaster related args from reversesshfs config on Windows
HostAgent's `sshConfig` already has some ControlMaster related args in `AdditionalArgs`, so it is necessary to remove them to avoid overrides above `Persist=false`. Signed-off-by: Norio Nomura <[email protected]>
1 parent 9d815d5 commit 9ad821b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pkg/hostagent/mount.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"fmt"
1010
"os"
1111
"runtime"
12+
"slices"
13+
"strings"
1214

1315
"github.com/lima-vm/sshocker/pkg/reversesshfs"
1416
"github.com/sirupsen/logrus"
@@ -76,6 +78,17 @@ func (a *HostAgent) setupMount(ctx context.Context, m limatype.Mount) (*mount, e
7678
// 2. these errors still imply additional coms over mux socket, which resulted sftp-server to fail more often statistically during test runs.
7779
// It is reasonable to disable this on Windows if required feature is not fully operational.
7880
rsf.SSHConfig.Persist = false
81+
82+
// HostAgent's `sshConfig` already has some ControlMaster related args in `AdditionalArgs`,
83+
// so it is necessary to remove them to avoid overrides above `Persist=false`.
84+
removePrefixedAdditionalArgs := func(prefix string) {
85+
if i := slices.IndexFunc(rsf.SSHConfig.AdditionalArgs, func(s string) bool { return strings.HasPrefix(s, prefix) }); i >= 0 {
86+
rsf.SSHConfig.AdditionalArgs = slices.Delete(rsf.SSHConfig.AdditionalArgs, i-1, i+1)
87+
}
88+
}
89+
removePrefixedAdditionalArgs("ControlMaster=")
90+
removePrefixedAdditionalArgs("ControlPath=")
91+
removePrefixedAdditionalArgs("ControlPersist=")
7992
}
8093
if err := rsf.Prepare(); err != nil {
8194
return nil, fmt.Errorf("failed to prepare reverse sshfs for %q on %q: %w", resolvedLocation, *m.MountPoint, err)

0 commit comments

Comments
 (0)