backends: pass error logger to backends

This commit is contained in:
Michael Eischer
2025-09-14 16:13:21 +02:00
parent 13f743e26b
commit 4dc71f24c5
31 changed files with 96 additions and 96 deletions

View File

@@ -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)
}

View File

@@ -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