2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-02 00:50:48 +00:00
restic/internal/fs/fs_reader_command.go

24 lines
566 B
Go
Raw Normal View History

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