mirror of
https://github.com/restic/restic.git
synced 2025-12-11 18:47:50 +00:00
backend/util: extract background handling code
This commit is contained in:
@@ -21,9 +21,9 @@ import (
|
|||||||
"github.com/restic/restic/internal/backend/limiter"
|
"github.com/restic/restic/internal/backend/limiter"
|
||||||
"github.com/restic/restic/internal/backend/location"
|
"github.com/restic/restic/internal/backend/location"
|
||||||
"github.com/restic/restic/internal/backend/rest"
|
"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/debug"
|
||||||
"github.com/restic/restic/internal/errors"
|
"github.com/restic/restic/internal/errors"
|
||||||
|
"github.com/restic/restic/internal/terminal"
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ func run(command string, args ...string) (*StdioConn, *sync.WaitGroup, chan stru
|
|||||||
cmd.Stdin = r
|
cmd.Stdin = r
|
||||||
cmd.Stdout = w
|
cmd.Stdout = w
|
||||||
|
|
||||||
bg, err := util.StartForeground(cmd)
|
bg, err := terminal.StartForeground(cmd)
|
||||||
// close rclone side of pipes
|
// close rclone side of pipes
|
||||||
errR := r.Close()
|
errR := r.Close()
|
||||||
errW := w.Close()
|
errW := w.Close()
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/restic/restic/internal/debug"
|
"github.com/restic/restic/internal/debug"
|
||||||
"github.com/restic/restic/internal/errors"
|
"github.com/restic/restic/internal/errors"
|
||||||
"github.com/restic/restic/internal/feature"
|
"github.com/restic/restic/internal/feature"
|
||||||
|
"github.com/restic/restic/internal/terminal"
|
||||||
|
|
||||||
"github.com/cenkalti/backoff/v4"
|
"github.com/cenkalti/backoff/v4"
|
||||||
"github.com/pkg/sftp"
|
"github.com/pkg/sftp"
|
||||||
@@ -84,7 +85,7 @@ func startClient(cfg Config) (*SFTP, error) {
|
|||||||
return nil, errors.Wrap(err, "cmd.StdoutPipe")
|
return nil, errors.Wrap(err, "cmd.StdoutPipe")
|
||||||
}
|
}
|
||||||
|
|
||||||
bg, err := util.StartForeground(cmd)
|
bg, err := terminal.StartForeground(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, exec.ErrDot) {
|
if errors.Is(err, exec.ErrDot) {
|
||||||
return nil, errors.Errorf("cannot implicitly run relative executable %v found in current directory, use -o sftp.command=./<command> to override", cmd.Path)
|
return nil, errors.Errorf("cannot implicitly run relative executable %v found in current directory, use -o sftp.command=./<command> to override", cmd.Path)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package util
|
package terminal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//go:build !windows
|
//go:build !windows
|
||||||
// +build !windows
|
// +build !windows
|
||||||
|
|
||||||
package util_test
|
package terminal_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/restic/restic/internal/backend/util"
|
"github.com/restic/restic/internal/terminal"
|
||||||
rtest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ func TestForeground(t *testing.T) {
|
|||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|
||||||
bg, err := util.StartForeground(cmd)
|
bg, err := terminal.StartForeground(cmd)
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
defer func() {
|
defer func() {
|
||||||
rtest.OK(t, cmd.Wait())
|
rtest.OK(t, cmd.Wait())
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
//go:build unix
|
//go:build unix
|
||||||
|
|
||||||
package util
|
package terminal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package util
|
package terminal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
Reference in New Issue
Block a user