2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 19:08:55 +00:00

rclone: Better field names for stdio conn

This commit is contained in:
Michael Eischer 2020-07-25 23:51:02 +02:00
parent 3cd927d180
commit 01b9581453
2 changed files with 18 additions and 18 deletions

View File

@ -88,8 +88,8 @@ func run(command string, args ...string) (*StdioConn, *exec.Cmd, *sync.WaitGroup
} }
c := &StdioConn{ c := &StdioConn{
stdin: stdout, receive: stdout,
stdout: stdin, send: stdin,
cmd: cmd, cmd: cmd,
} }

View File

@ -12,28 +12,28 @@ import (
// StdioConn implements a net.Conn via stdin/stdout. // StdioConn implements a net.Conn via stdin/stdout.
type StdioConn struct { type StdioConn struct {
stdin *os.File receive *os.File
stdout *os.File send *os.File
cmd *exec.Cmd cmd *exec.Cmd
closeIn sync.Once closeRecv sync.Once
closeOut sync.Once closeSend sync.Once
} }
func (s *StdioConn) Read(p []byte) (int, error) { func (s *StdioConn) Read(p []byte) (int, error) {
n, err := s.stdin.Read(p) n, err := s.receive.Read(p)
return n, err return n, err
} }
func (s *StdioConn) Write(p []byte) (int, error) { func (s *StdioConn) Write(p []byte) (int, error) {
n, err := s.stdout.Write(p) n, err := s.send.Write(p)
return n, err return n, err
} }
// Close closes the stream to the child process. // Close closes the stream to the child process.
func (s *StdioConn) Close() (err error) { func (s *StdioConn) Close() (err error) {
s.closeOut.Do(func() { s.closeSend.Do(func() {
debug.Log("close stdio send connection") debug.Log("close stdio send connection")
err = s.stdout.Close() err = s.send.Close()
}) })
return err return err
@ -43,9 +43,9 @@ func (s *StdioConn) Close() (err error) {
func (s *StdioConn) CloseAll() (err error) { func (s *StdioConn) CloseAll() (err error) {
err = s.Close() err = s.Close()
s.closeIn.Do(func() { s.closeRecv.Do(func() {
debug.Log("close stdio receive connection") debug.Log("close stdio receive connection")
err2 := s.stdin.Close() err2 := s.receive.Close()
if err == nil { if err == nil {
err = err2 err = err2
} }
@ -66,8 +66,8 @@ func (s *StdioConn) RemoteAddr() net.Addr {
// SetDeadline sets the read/write deadline. // SetDeadline sets the read/write deadline.
func (s *StdioConn) SetDeadline(t time.Time) error { func (s *StdioConn) SetDeadline(t time.Time) error {
err1 := s.stdin.SetReadDeadline(t) err1 := s.receive.SetReadDeadline(t)
err2 := s.stdout.SetWriteDeadline(t) err2 := s.send.SetWriteDeadline(t)
if err1 != nil { if err1 != nil {
return err1 return err1
} }
@ -76,12 +76,12 @@ func (s *StdioConn) SetDeadline(t time.Time) error {
// SetReadDeadline sets the read/write deadline. // SetReadDeadline sets the read/write deadline.
func (s *StdioConn) SetReadDeadline(t time.Time) error { func (s *StdioConn) SetReadDeadline(t time.Time) error {
return s.stdin.SetReadDeadline(t) return s.receive.SetReadDeadline(t)
} }
// SetWriteDeadline sets the read/write deadline. // SetWriteDeadline sets the read/write deadline.
func (s *StdioConn) SetWriteDeadline(t time.Time) error { func (s *StdioConn) SetWriteDeadline(t time.Time) error {
return s.stdout.SetWriteDeadline(t) return s.send.SetWriteDeadline(t)
} }
// make sure StdioConn implements net.Conn // make sure StdioConn implements net.Conn