Merge pull request #3499 from greatroar/wrappedconn-pointer

rclone: Return one fewer value from run
This commit is contained in:
MichaelEischer 2021-08-31 21:48:36 +02:00 committed by GitHub
commit ec2e3b260e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 7 deletions

View File

@ -36,12 +36,12 @@ type Backend struct {
}
// run starts command with args and initializes the StdioConn.
func run(command string, args ...string) (*StdioConn, *exec.Cmd, *sync.WaitGroup, func() error, error) {
func run(command string, args ...string) (*StdioConn, *sync.WaitGroup, func() error, error) {
cmd := exec.Command(command, args...)
p, err := cmd.StderrPipe()
if err != nil {
return nil, nil, nil, nil, err
return nil, nil, nil, err
}
var wg sync.WaitGroup
@ -58,7 +58,7 @@ func run(command string, args ...string) (*StdioConn, *exec.Cmd, *sync.WaitGroup
r, stdin, err := os.Pipe()
if err != nil {
return nil, nil, nil, nil, err
return nil, nil, nil, err
}
stdout, w, err := os.Pipe()
@ -66,7 +66,7 @@ func run(command string, args ...string) (*StdioConn, *exec.Cmd, *sync.WaitGroup
// close first pipe and ignore subsequent errors
_ = r.Close()
_ = stdin.Close()
return nil, nil, nil, nil, err
return nil, nil, nil, err
}
cmd.Stdin = r
@ -84,7 +84,7 @@ func run(command string, args ...string) (*StdioConn, *exec.Cmd, *sync.WaitGroup
err = errW
}
if err != nil {
return nil, nil, nil, nil, err
return nil, nil, nil, err
}
c := &StdioConn{
@ -93,7 +93,7 @@ func run(command string, args ...string) (*StdioConn, *exec.Cmd, *sync.WaitGroup
cmd: cmd,
}
return c, cmd, &wg, bg, nil
return c, &wg, bg, nil
}
// wrappedConn adds bandwidth limiting capabilities to the StdioConn by
@ -157,7 +157,7 @@ func newBackend(cfg Config, lim limiter.Limiter) (*Backend, error) {
arg0, args := args[0], args[1:]
debug.Log("running command: %v %v", arg0, args)
stdioConn, cmd, wg, bg, err := run(arg0, args...)
stdioConn, wg, bg, err := run(arg0, args...)
if err != nil {
return nil, err
}
@ -181,6 +181,7 @@ func newBackend(cfg Config, lim limiter.Limiter) (*Backend, error) {
},
}
cmd := stdioConn.cmd
waitCh := make(chan struct{})
be := &Backend{
tr: tr,