Skip to content

Commit 7e68c08

Browse files
committed
refactor(wsl): improve wsl check env code
Signed-off-by: Kevin Cui <bh@bugs.cc>
1 parent e1d6856 commit 7e68c08

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

pkg/cli/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (c *InitContext) Start() error {
8989
return util.WaitBindPID(ctx, c.Logger, c.BindPID)
9090
})
9191

92-
wsl.Check(&c.InitOpt)
92+
wsl.CheckEnv(&c.InitOpt)
9393

9494
select {
9595
case <-ctx.Done():

pkg/wsl/check.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var (
2424
_isFeatureEnabled bool
2525
)
2626

27-
func Check(opt *types.InitOpt) {
27+
func CheckEnv(opt *types.InitOpt) {
2828
log := opt.Logger
2929

3030
if isEnabled := isFeatureEnabled(log); !isEnabled {
@@ -36,21 +36,20 @@ func Check(opt *types.InitOpt) {
3636

3737
log.Info("WSL2 feature is already enabled")
3838

39-
shouldUpdate, err := shouldUpdateWSL(log)
40-
if err == nil && !shouldUpdate {
41-
log.Info("WSL2 is up to date")
42-
channel.NotifyWSLEnvReady()
43-
return
44-
}
39+
if shouldUpdate, err := shouldUpdateWSL(log); shouldUpdate {
40+
if err != nil {
41+
log.Warnf("Failed to check if WSL2 needs to be updated: %v", err)
42+
} else {
43+
log.Info("WSL2 needs to be updated")
44+
}
4545

46-
if err != nil {
47-
log.Warnf("Failed to check if WSL2 needs to be updated: %v", err)
48-
} else {
49-
log.Info("WSL2 needs to be updated")
46+
event.NotifyInit(event.NeedUpdateWSL)
47+
opt.CanUpdateWSL = true
48+
return
5049
}
5150

52-
event.NotifyInit(event.NeedUpdateWSL)
53-
opt.CanUpdateWSL = true
51+
log.Info("WSL2 is up to date")
52+
channel.NotifyWSLEnvReady()
5453
return
5554
}
5655

0 commit comments

Comments
 (0)