mirror of
https://github.com/restic/restic.git
synced 2025-12-11 18:47:50 +00:00
backends: pass error logger to backends
This commit is contained in:
@@ -39,7 +39,7 @@ func TestLayout(t *testing.T) {
|
||||
Command: fmt.Sprintf("%q -e", sftpServer),
|
||||
Path: repo,
|
||||
Connections: 5,
|
||||
})
|
||||
}, t.Logf)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func NewFactory() location.Factory {
|
||||
return location.NewLimitedBackendFactory("sftp", ParseConfig, location.NoPassword, limiter.WrapBackendConstructor(Create), limiter.WrapBackendConstructor(Open))
|
||||
}
|
||||
|
||||
func startClient(cfg Config) (*SFTP, error) {
|
||||
func startClient(cfg Config, errorLog func(string, ...interface{})) (*SFTP, error) {
|
||||
program, args, err := buildSSHCommand(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -71,7 +71,7 @@ func startClient(cfg Config) (*SFTP, error) {
|
||||
go func() {
|
||||
sc := bufio.NewScanner(stderr)
|
||||
for sc.Scan() {
|
||||
fmt.Fprintf(os.Stderr, "subprocess %v: %v\n", program, sc.Text())
|
||||
errorLog("subprocess %v: %v\n", program, sc.Text())
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -144,10 +144,10 @@ func (r *SFTP) clientError() error {
|
||||
|
||||
// Open opens an sftp backend as described by the config by running
|
||||
// "ssh" with the appropriate arguments (or cfg.Command, if set).
|
||||
func Open(_ context.Context, cfg Config) (*SFTP, error) {
|
||||
func Open(_ context.Context, cfg Config, errorLog func(string, ...interface{})) (*SFTP, error) {
|
||||
debug.Log("open backend with config %#v", cfg)
|
||||
|
||||
sftp, err := startClient(cfg)
|
||||
sftp, err := startClient(cfg, errorLog)
|
||||
if err != nil {
|
||||
debug.Log("unable to start program: %v", err)
|
||||
return nil, err
|
||||
@@ -240,8 +240,8 @@ func buildSSHCommand(cfg Config) (cmd string, args []string, err error) {
|
||||
|
||||
// Create creates an sftp backend as described by the config by running "ssh"
|
||||
// with the appropriate arguments (or cfg.Command, if set).
|
||||
func Create(ctx context.Context, cfg Config) (*SFTP, error) {
|
||||
sftp, err := startClient(cfg)
|
||||
func Create(ctx context.Context, cfg Config, errorLog func(string, ...interface{})) (*SFTP, error) {
|
||||
sftp, err := startClient(cfg, errorLog)
|
||||
if err != nil {
|
||||
debug.Log("unable to start program: %v", err)
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user