Skip to content

Commit

Permalink
fix: skip fuse check when kernel is WSL2
Browse files Browse the repository at this point in the history
Signed-off-by: NaturalSelect <[email protected]>
  • Loading branch information
NaturalSelect committed Sep 26, 2023
1 parent a13b532 commit b02a94e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/task/step/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"os"
"strings"

comm "github.com/opencurve/curveadm/internal/common"
"github.com/opencurve/curveadm/internal/errno"
"github.com/opencurve/curveadm/internal/task/context"
"github.com/opencurve/curveadm/internal/utils"
Expand Down Expand Up @@ -475,6 +476,15 @@ func (s *UnixName) Execute(ctx *context.Context) error {
}

func (s *ModInfo) Execute(ctx *context.Context) error {
isWsl2, err := ctx.Module().Shell().IsWsl2()
if err == nil && isWsl2 {
// NOTE: FUSE is statically compiled into the WSL2 kernel
// See also: https://github.com/microsoft/WSL/issues/17#issuecomment-759817472
if s.Name == comm.KERNERL_MODULE_FUSE {
*s.Success = true
return nil
}
}
cmd := ctx.Module().Shell().ModInfo(s.Name)
out, err := cmd.Execute(s.ExecOptions)
return PostHandle(s.Success, s.Out, out, err, errno.ERR_GET_KERNEL_MODULE_INFO_FAILED)
Expand Down
12 changes: 12 additions & 0 deletions pkg/module/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ func (s *Shell) Execute(options ExecOptions) (string, error) {
return execCommand(s.sshClient, s.tmpl, s.data, options)
}

func (s *Shell) IsWsl2() (isWsl2 bool, err error) {
cmd := s.Command("uname -a | grep \"WSL2\" | wc -l")
out, err := cmd.Execute(ExecOptions{})
if err != nil {
return
}
if out != "" && out[0] == '1' {
isWsl2 = true
}
return
}

// text
func (s *Shell) Sed(file ...string) *Shell {
s.tmpl = template.Must(template.New("sed").Parse(TEMPLATE_SED))
Expand Down

0 comments on commit b02a94e

Please sign in to comment.