1
0
mirror of https://github.com/rancher/os.git synced 2025-09-01 23:04:41 +00:00

Update vendor

This commit is contained in:
Darren Shepherd
2016-05-31 18:12:52 -07:00
parent 410dfbe0fd
commit a14846152b
1253 changed files with 222820 additions and 15054 deletions

View File

@@ -0,0 +1,54 @@
package exec
import (
"bytes"
"errors"
)
// Below is largely a copy from go's os/exec/exec.go
// Run starts the specified command and waits for it to complete.
//
// The returned error is nil if the command runs, has no problems
// copying stdin, stdout, and stderr, and exits with a zero exit
// status.
//
// If the command fails to run or doesn't complete successfully, the
// error is of type *ExitError. Other error types may be
// returned for I/O problems.
func (c *Cmd) Run() error {
if err := c.Start(); err != nil {
return translateError(err)
}
return translateError(c.Wait())
}
// Output runs the command and returns its standard output.
// Any returned error will usually be of type *ExitError.
// If c.Stderr was nil, Output populates ExitError.Stderr.
func (c *Cmd) Output() ([]byte, error) {
if c.Stdout != nil {
return nil, errors.New("exec: Stdout already set")
}
var stdout bytes.Buffer
c.Stdout = &stdout
err := c.Run()
return stdout.Bytes(), err
}
// CombinedOutput runs the command and returns its combined standard
// output and standard error.
func (c *Cmd) CombinedOutput() ([]byte, error) {
if c.Stdout != nil {
return nil, errors.New("exec: Stdout already set")
}
if c.Stderr != nil {
return nil, errors.New("exec: Stderr already set")
}
var b bytes.Buffer
c.Stdout = &b
c.Stderr = &b
err := c.Run()
return b.Bytes(), err
}

View File

@@ -0,0 +1,81 @@
package exec
import (
"fmt"
osExec "os/exec"
"strconv"
"github.com/docker/containerd/subreaper"
)
var ErrNotFound = osExec.ErrNotFound
type Cmd struct {
osExec.Cmd
err error
sub *subreaper.Subscription
}
type Error struct {
Name string
Err error
}
func (e *Error) Error() string {
return "exec: " + strconv.Quote(e.Name) + ": " + e.Err.Error()
}
type ExitCodeError struct {
Code int
}
func (e ExitCodeError) Error() string {
return fmt.Sprintf("Non-zero exit code: %d", e.Code)
}
func LookPath(file string) (string, error) {
v, err := osExec.LookPath(file)
return v, translateError(err)
}
func Command(name string, args ...string) *Cmd {
return &Cmd{
Cmd: *osExec.Command(name, args...),
}
}
func (c *Cmd) Start() error {
c.sub = subreaper.Subscribe()
err := c.Cmd.Start()
if err != nil {
subreaper.Unsubscribe(c.sub)
c.sub = nil
c.err = translateError(err)
return c.err
}
c.sub.SetPid(c.Cmd.Process.Pid)
return nil
}
func (c *Cmd) Wait() error {
if c.sub == nil {
return c.err
}
exitCode := c.sub.Wait()
if exitCode == 0 {
return nil
}
return ExitCodeError{Code: exitCode}
}
func translateError(err error) error {
switch v := err.(type) {
case *osExec.Error:
return &Error{
Name: v.Name,
Err: v.Err,
}
}
return err
}