From 6ff7cd90507657caa12a5c46ff797bf2a72a077f Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 7 Sep 2025 11:58:02 +0200 Subject: [PATCH] backend/util: extract background handling code --- internal/backend/rclone/backend.go | 4 ++-- internal/backend/sftp/sftp.go | 3 ++- internal/{backend/util => terminal}/foreground.go | 2 +- internal/{backend/util => terminal}/foreground_test.go | 6 +++--- internal/{backend/util => terminal}/foreground_unix.go | 2 +- internal/{backend/util => terminal}/foreground_windows.go | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) rename internal/{backend/util => terminal}/foreground.go (97%) rename internal/{backend/util => terminal}/foreground_test.go (84%) rename internal/{backend/util => terminal}/foreground_unix.go (99%) rename internal/{backend/util => terminal}/foreground_windows.go (96%) diff --git a/internal/backend/rclone/backend.go b/internal/backend/rclone/backend.go index 74b2148ce..5ee330a69 100644 --- a/internal/backend/rclone/backend.go +++ b/internal/backend/rclone/backend.go @@ -21,9 +21,9 @@ import ( "github.com/restic/restic/internal/backend/limiter" "github.com/restic/restic/internal/backend/location" "github.com/restic/restic/internal/backend/rest" - "github.com/restic/restic/internal/backend/util" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" + "github.com/restic/restic/internal/terminal" "golang.org/x/net/http2" ) @@ -82,7 +82,7 @@ func run(command string, args ...string) (*StdioConn, *sync.WaitGroup, chan stru cmd.Stdin = r cmd.Stdout = w - bg, err := util.StartForeground(cmd) + bg, err := terminal.StartForeground(cmd) // close rclone side of pipes errR := r.Close() errW := w.Close() diff --git a/internal/backend/sftp/sftp.go b/internal/backend/sftp/sftp.go index c735b9b3a..78757a249 100644 --- a/internal/backend/sftp/sftp.go +++ b/internal/backend/sftp/sftp.go @@ -21,6 +21,7 @@ import ( "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/feature" + "github.com/restic/restic/internal/terminal" "github.com/cenkalti/backoff/v4" "github.com/pkg/sftp" @@ -84,7 +85,7 @@ func startClient(cfg Config) (*SFTP, error) { return nil, errors.Wrap(err, "cmd.StdoutPipe") } - bg, err := util.StartForeground(cmd) + bg, err := terminal.StartForeground(cmd) if err != nil { if errors.Is(err, exec.ErrDot) { return nil, errors.Errorf("cannot implicitly run relative executable %v found in current directory, use -o sftp.command=./ to override", cmd.Path) diff --git a/internal/backend/util/foreground.go b/internal/terminal/foreground.go similarity index 97% rename from internal/backend/util/foreground.go rename to internal/terminal/foreground.go index 477fc8900..e3c1ff0b5 100644 --- a/internal/backend/util/foreground.go +++ b/internal/terminal/foreground.go @@ -1,4 +1,4 @@ -package util +package terminal import ( "os" diff --git a/internal/backend/util/foreground_test.go b/internal/terminal/foreground_test.go similarity index 84% rename from internal/backend/util/foreground_test.go rename to internal/terminal/foreground_test.go index c26861a6c..c8392ab88 100644 --- a/internal/backend/util/foreground_test.go +++ b/internal/terminal/foreground_test.go @@ -1,7 +1,7 @@ //go:build !windows // +build !windows -package util_test +package terminal_test import ( "bufio" @@ -10,7 +10,7 @@ import ( "strings" "testing" - "github.com/restic/restic/internal/backend/util" + "github.com/restic/restic/internal/terminal" rtest "github.com/restic/restic/internal/test" ) @@ -22,7 +22,7 @@ func TestForeground(t *testing.T) { stdout, err := cmd.StdoutPipe() rtest.OK(t, err) - bg, err := util.StartForeground(cmd) + bg, err := terminal.StartForeground(cmd) rtest.OK(t, err) defer func() { rtest.OK(t, cmd.Wait()) diff --git a/internal/backend/util/foreground_unix.go b/internal/terminal/foreground_unix.go similarity index 99% rename from internal/backend/util/foreground_unix.go rename to internal/terminal/foreground_unix.go index 3952885f8..340f80791 100644 --- a/internal/backend/util/foreground_unix.go +++ b/internal/terminal/foreground_unix.go @@ -1,6 +1,6 @@ //go:build unix -package util +package terminal import ( "os" diff --git a/internal/backend/util/foreground_windows.go b/internal/terminal/foreground_windows.go similarity index 96% rename from internal/backend/util/foreground_windows.go rename to internal/terminal/foreground_windows.go index f9b753c35..8c541fe47 100644 --- a/internal/backend/util/foreground_windows.go +++ b/internal/terminal/foreground_windows.go @@ -1,4 +1,4 @@ -package util +package terminal import ( "os/exec"