mirror of
https://github.com/restic/restic.git
synced 2025-12-04 01:11:56 +00:00
rclone/sftp: Improve handling of ErrDot errors
Restic now yields a more informative error message when exec.ErrDot occurs.
This commit is contained in:
20
internal/backend/errdot_119.go
Normal file
20
internal/backend/errdot_119.go
Normal file
@@ -0,0 +1,20 @@
|
||||
//go:build go1.19
|
||||
// +build go1.19
|
||||
|
||||
// This file provides a function to check whether an error from cmd.Start() is
|
||||
// exec.ErrDot which was introduced in Go 1.19.
|
||||
// This function is needed so that we can perform this check only for Go 1.19 and
|
||||
// up, whereas for older versions we use a dummy/stub in the file errdot_old.go.
|
||||
// Once the minimum Go version restic supports is 1.19, remove this file and
|
||||
// replace any calls to it with the corresponding code as per below.
|
||||
|
||||
package backend
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func IsErrDot(err error) bool {
|
||||
return errors.Is(err, exec.ErrDot)
|
||||
}
|
||||
13
internal/backend/errdot_old.go
Normal file
13
internal/backend/errdot_old.go
Normal file
@@ -0,0 +1,13 @@
|
||||
//go:build !go1.19
|
||||
// +build !go1.19
|
||||
|
||||
// This file provides a stub for IsErrDot() for Go versions below 1.19.
|
||||
// See the corresponding file errdot_119.go for more information.
|
||||
// Once the minimum Go version restic supports is 1.19, remove this file
|
||||
// and perform the actions listed in errdot_119.go.
|
||||
|
||||
package backend
|
||||
|
||||
func IsErrDot(err error) bool {
|
||||
return false
|
||||
}
|
||||
@@ -85,6 +85,9 @@ func run(command string, args ...string) (*StdioConn, *sync.WaitGroup, func() er
|
||||
err = errW
|
||||
}
|
||||
if err != nil {
|
||||
if backend.IsErrDot(err) {
|
||||
return nil, nil, nil, errors.Errorf("cannot implicitly run relative executable %v found in current directory, use -o rclone.program=./<program> to override", cmd.Path)
|
||||
}
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,10 @@ func startClient(cfg Config) (*SFTP, error) {
|
||||
|
||||
bg, err := backend.StartForeground(cmd)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "cmd.Start")
|
||||
if backend.IsErrDot(err) {
|
||||
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, err
|
||||
}
|
||||
|
||||
// wait in a different goroutine
|
||||
|
||||
Reference in New Issue
Block a user