From cf4cf94418a777c776d6b2583719d2e7db618375 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Tue, 13 Mar 2018 21:09:16 +0100 Subject: [PATCH] Move backend/sftp.StartForeground to backend/ --- internal/backend/{sftp => }/foreground_solaris.go | 7 +++++-- internal/backend/{sftp => }/foreground_unix.go | 6 +++--- internal/backend/{sftp => }/foreground_windows.go | 4 ++-- internal/backend/sftp/sftp.go | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) rename internal/backend/{sftp => }/foreground_solaris.go (58%) rename internal/backend/{sftp => }/foreground_unix.go (91%) rename internal/backend/{sftp => }/foreground_windows.go (84%) diff --git a/internal/backend/sftp/foreground_solaris.go b/internal/backend/foreground_solaris.go similarity index 58% rename from internal/backend/sftp/foreground_solaris.go rename to internal/backend/foreground_solaris.go index 5114eb9ea..501f9c1a1 100644 --- a/internal/backend/sftp/foreground_solaris.go +++ b/internal/backend/foreground_solaris.go @@ -1,4 +1,4 @@ -package sftp +package backend import ( "os/exec" @@ -7,7 +7,10 @@ import ( "github.com/restic/restic/internal/errors" ) -func startForeground(cmd *exec.Cmd) (bg func() error, err error) { +// StartForeground runs cmd in the foreground, by temporarily switching to the +// new process group created for cmd. The returned function `bg` switches back +// to the previous process group. +func StartForeground(cmd *exec.Cmd) (bg func() error, err error) { // run the command in it's own process group so that SIGINT // is not sent to it. cmd.SysProcAttr = &syscall.SysProcAttr{ diff --git a/internal/backend/sftp/foreground_unix.go b/internal/backend/foreground_unix.go similarity index 91% rename from internal/backend/sftp/foreground_unix.go rename to internal/backend/foreground_unix.go index 789cecb1c..1662a0250 100644 --- a/internal/backend/sftp/foreground_unix.go +++ b/internal/backend/foreground_unix.go @@ -1,7 +1,7 @@ // +build !solaris // +build !windows -package sftp +package backend import ( "os" @@ -24,10 +24,10 @@ func tcsetpgrp(fd int, pid int) error { return errno } -// startForeground runs cmd in the foreground, by temporarily switching to the +// StartForeground runs cmd in the foreground, by temporarily switching to the // new process group created for cmd. The returned function `bg` switches back // to the previous process group. -func startForeground(cmd *exec.Cmd) (bg func() error, err error) { +func StartForeground(cmd *exec.Cmd) (bg func() error, err error) { // open the TTY, we need the file descriptor tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0) if err != nil { diff --git a/internal/backend/sftp/foreground_windows.go b/internal/backend/foreground_windows.go similarity index 84% rename from internal/backend/sftp/foreground_windows.go rename to internal/backend/foreground_windows.go index e57b4d3a4..0e8b03a13 100644 --- a/internal/backend/sftp/foreground_windows.go +++ b/internal/backend/foreground_windows.go @@ -1,4 +1,4 @@ -package sftp +package backend import ( "os/exec" @@ -6,7 +6,7 @@ import ( "github.com/restic/restic/internal/errors" ) -// startForeground runs cmd in the foreground, by temporarily switching to the +// StartForeground runs cmd in the foreground, by temporarily switching to the // new process group created for cmd. The returned function `bg` switches back // to the previous process group. func startForeground(cmd *exec.Cmd) (bg func() error, err error) { diff --git a/internal/backend/sftp/sftp.go b/internal/backend/sftp/sftp.go index 1f98cf56b..268a3404a 100644 --- a/internal/backend/sftp/sftp.go +++ b/internal/backend/sftp/sftp.go @@ -65,7 +65,7 @@ func startClient(program string, args ...string) (*SFTP, error) { return nil, errors.Wrap(err, "cmd.StdoutPipe") } - bg, err := startForeground(cmd) + bg, err := backend.StartForeground(cmd) if err != nil { return nil, errors.Wrap(err, "cmd.Start") }