stdin-from-command: implemented suggestions in #4254
The code has been refactored so that the archiver is back to the original code, and the stderr is handled using a go routine to avoid deadlock.
This commit is contained in:
parent
c133065a9f
commit
4e5caab114
3 changed files with 55 additions and 31 deletions
23
internal/fs/fs_reader_command.go
Normal file
23
internal/fs/fs_reader_command.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// ReadCloserCommand wraps an exec.Cmd and its standard output to provide an
|
||||
// io.ReadCloser that waits for the command to terminate on Close(), reporting
|
||||
// any error in the command.Wait() function back to the Close() caller.
|
||||
type ReadCloserCommand struct {
|
||||
Cmd *exec.Cmd
|
||||
Stdout io.ReadCloser
|
||||
}
|
||||
|
||||
func (fp *ReadCloserCommand) Read(p []byte) (n int, err error) {
|
||||
return fp.Stdout.Read(p)
|
||||
}
|
||||
|
||||
func (fp *ReadCloserCommand) Close() error {
|
||||
// No need to close fp.Stdout as Wait() closes all pipes.
|
||||
return fp.Cmd.Wait()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue