chore(ci): enable noctx linter (#4972)

* pass context in webdav helpers
* fix typo in function name
This commit is contained in:
Nathan Baulch
2025-11-20 16:46:28 +11:00
committed by GitHub
parent c048f656d7
commit ea1bdb1541
10 changed files with 22 additions and 18 deletions

View File

@@ -97,7 +97,6 @@ linters:
- nakedret # already enforced by gofumpt in a stricter manner
- nilnil
- nlreturn # already enforced by wsl_v5
- noctx
- noinlineerr # inline error handling is a common Go idiom used in this codebase
- nonamedreturns
- paralleltest

View File

@@ -48,9 +48,9 @@ func (c *commandServerStart) startServerWithOptionalTLS(ctx context.Context, htt
switch len(listeners) {
case 0:
if after, ok := strings.CutPrefix(httpServer.Addr, "unix:"); ok {
l, err = net.Listen("unix", after)
l, err = (&net.ListenConfig{}).Listen(ctx, "unix", after)
} else {
l, err = net.Listen("tcp", httpServer.Addr)
l, err = (&net.ListenConfig{}).Listen(ctx, "tcp", httpServer.Addr)
}
if err != nil {

View File

@@ -224,8 +224,8 @@ func NewKopiaAPIClient(options Options) (*KopiaAPIClient, error) {
tp, _ := transport.(*http.Transport)
transport = tp.Clone()
tp, _ = transport.(*http.Transport)
tp.DialContext = func(_ context.Context, _, _ string) (net.Conn, error) {
dial, err := net.Dial("unix", u.Path)
tp.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) {
dial, err := (&net.Dialer{}).DialContext(ctx, "unix", u.Path)
return dial, errors.Wrap(err, "Failed to connect to socket: "+options.BaseURL)
}
}

View File

@@ -36,7 +36,7 @@ func newPosixWedavController(ctx context.Context, entry fs.Directory, mountPoint
}
func (c posixWedavController) Unmount(ctx context.Context) error {
if err := unmountWebDevHelper(ctx, c.mountPoint); err != nil {
if err := unmountWebDavHelper(ctx, c.mountPoint); err != nil {
return err
}

View File

@@ -7,8 +7,8 @@
"github.com/pkg/errors"
)
func mountWebDavHelper(_ context.Context, url, path string) error {
mount := exec.Command("/sbin/mount", "-t", "webdav", "-r", url, path)
func mountWebDavHelper(ctx context.Context, url, path string) error {
mount := exec.CommandContext(ctx, "/sbin/mount", "-t", "webdav", "-r", url, path)
if err := mount.Run(); err != nil {
return errors.Errorf("webdav mount %q on %q failed: %v", url, path, err)
}
@@ -16,8 +16,8 @@ func mountWebDavHelper(_ context.Context, url, path string) error {
return nil
}
func unmountWebDevHelper(_ context.Context, path string) error {
unmount := exec.Command("/usr/sbin/diskutil", "unmount", path)
func unmountWebDavHelper(ctx context.Context, path string) error {
unmount := exec.CommandContext(ctx, "/usr/sbin/diskutil", "unmount", path)
if err := unmount.Run(); err != nil {
return errors.Errorf("unmount %q failed: %v", path, err)
}

View File

@@ -6,7 +6,7 @@
)
func mountWebDavHelper(ctx context.Context, url, path string) error {
mount := exec.Command("/usr/bin/mount", "-t", "davfs", "-r", url, path)
mount := exec.CommandContext(ctx, "/usr/bin/mount", "-t", "davfs", "-r", url, path)
if err := mount.Run(); err != nil {
log(ctx).Errorf("mount command failed: %v. Cowardly refusing to run with root permissions. Try \"sudo /usr/bin/mount -t davfs -r %s %s\"\n", err, url, path)
}
@@ -14,8 +14,8 @@ func mountWebDavHelper(ctx context.Context, url, path string) error {
return nil
}
func unmountWebDevHelper(ctx context.Context, path string) error {
unmount := exec.Command("/usr/bin/umount", path)
func unmountWebDavHelper(ctx context.Context, path string) error {
unmount := exec.CommandContext(ctx, "/usr/bin/umount", path)
if err := unmount.Run(); err != nil {
log(ctx).Errorf("umount command failed: %v. Cowardly refusing to run with root permissions. Try \"sudo /usr/bin/umount %s\"\n", err, path)
}

View File

@@ -46,7 +46,7 @@ func DirectoryWebDAV(ctx context.Context, entry fs.Directory) (Controller, error
Logger: logger,
})
l, err := net.Listen("tcp", "127.0.0.1:0")
l, err := (&net.ListenConfig{}).Listen(ctx, "tcp", "127.0.0.1:0")
if err != nil {
return nil, errors.Wrap(err, "listen error")
}

View File

@@ -339,7 +339,7 @@ func New(ctx context.Context, opt *Options, isCreate bool) (blob.Storage, error)
"--vfs-write-back=0s", // disable write-back, critical for correctness
)
r.cmd = exec.Command(rcloneExe, arguments...) //nolint:gosec
r.cmd = exec.CommandContext(ctx, rcloneExe, arguments...) //nolint:gosec
r.cmd.Env = append(r.cmd.Env, opt.RCloneEnv...)
// https://github.com/kopia/kopia/issues/1934

View File

@@ -465,7 +465,7 @@ func getSFTPClientExternal(ctx context.Context, opt *Options) (*sftpConnection,
log(ctx).Debugf("launching external SSH process %v %v", sshCommand, strings.Join(cmdArgs, " "))
cmd := exec.Command(sshCommand, cmdArgs...) //nolint:gosec
cmd := exec.CommandContext(ctx, sshCommand, cmdArgs...) //nolint:gosec
// send errors from ssh to stderr
cmd.Stderr = os.Stderr

View File

@@ -3,6 +3,7 @@
import (
"bytes"
"context"
"log"
"os"
"os/exec"
@@ -63,8 +64,10 @@ func (kr *Runner) Cleanup() {
func (kr *Runner) Run(args ...string) (stdout, stderr string, err error) {
argsStr := strings.Join(args, " ")
log.Printf("running '%s %v'", kr.Exe, argsStr)
cmdArgs := append(append([]string(nil), kr.fixedArgs...), args...)
c := exec.Command(kr.Exe, cmdArgs...)
ctx := context.Background()
c := exec.CommandContext(ctx, kr.Exe, cmdArgs...)
c.Env = append(os.Environ(), kr.environment...)
errOut := &bytes.Buffer{}
@@ -79,9 +82,11 @@ func (kr *Runner) Run(args ...string) (stdout, stderr string, err error) {
// RunAsync will execute the kopia command with the given args in background.
func (kr *Runner) RunAsync(args ...string) (*exec.Cmd, error) {
log.Printf("running async '%s %v'", kr.Exe, strings.Join(args, " "))
cmdArgs := append(append([]string(nil), kr.fixedArgs...), args...)
ctx := context.Background()
//nolint:gosec //G204
c := exec.Command(kr.Exe, cmdArgs...)
c := exec.CommandContext(ctx, kr.Exe, cmdArgs...)
c.Env = append(os.Environ(), kr.environment...)
c.Stderr = &bytes.Buffer{}