Skip to content

Commit db7f60f

Browse files
authored
Merge pull request #2497 from alexandear/change/with-context-non-pointer-ctx
executil: change ctx parameter to be non-pointer
2 parents 65ae991 + 119883a commit db7f60f

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

pkg/executil/command.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ import (
1010
)
1111

1212
type options struct {
13-
ctx *context.Context
13+
ctx context.Context
1414
}
1515

1616
type Opt func(*options) error
1717

1818
// WithContext runs the command with CommandContext.
19-
//
20-
//nolint:gocritic // consider `ctx' to be of non-pointer type
21-
func WithContext(ctx *context.Context) Opt {
19+
func WithContext(ctx context.Context) Opt {
2220
return func(o *options) error {
2321
o.ctx = ctx
2422
return nil
@@ -35,7 +33,7 @@ func RunUTF16leCommand(args []string, opts ...Opt) (string, error) {
3533

3634
var cmd *exec.Cmd
3735
if o.ctx != nil {
38-
cmd = exec.CommandContext(*o.ctx, args[0], args[1:]...)
36+
cmd = exec.CommandContext(o.ctx, args[0], args[1:]...)
3937
} else {
4038
cmd = exec.Command(args[0], args[1:]...)
4139
}

pkg/wsl2/vm_windows.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func startVM(ctx context.Context, distroName string) error {
2323
"wsl.exe",
2424
"--distribution",
2525
distroName,
26-
}, executil.WithContext(&ctx))
26+
}, executil.WithContext(ctx))
2727
if err != nil {
2828
return fmt.Errorf("failed to run `wsl.exe --distribution %s`: %w (out=%q)",
2929
distroName, err, string(out))
@@ -41,7 +41,7 @@ func initVM(ctx context.Context, instanceDir, distroName string) error {
4141
distroName,
4242
instanceDir,
4343
baseDisk,
44-
}, executil.WithContext(&ctx))
44+
}, executil.WithContext(ctx))
4545
if err != nil {
4646
return fmt.Errorf("failed to run `wsl.exe --import %s %s %s`: %w (out=%q)",
4747
distroName, instanceDir, baseDisk, err, string(out))
@@ -55,7 +55,7 @@ func stopVM(ctx context.Context, distroName string) error {
5555
"wsl.exe",
5656
"--terminate",
5757
distroName,
58-
}, executil.WithContext(&ctx))
58+
}, executil.WithContext(ctx))
5959
if err != nil {
6060
return fmt.Errorf("failed to run `wsl.exe --terminate %s`: %w (out=%q)",
6161
distroName, err, string(out))
@@ -164,7 +164,7 @@ func unregisterVM(ctx context.Context, distroName string) error {
164164
"wsl.exe",
165165
"--unregister",
166166
distroName,
167-
}, executil.WithContext(&ctx))
167+
}, executil.WithContext(ctx))
168168
if err != nil {
169169
return fmt.Errorf("failed to run `wsl.exe --unregister %s`: %w (out=%q)",
170170
distroName, err, string(out))

0 commit comments

Comments
 (0)