Skip to content

Commit

Permalink
Don't merge stdout/stderr on remote device-info.
Browse files Browse the repository at this point in the history
If the remote device-info produces stderr output, but does not
fail, we should log it, but not try to parse it as json.

Also clean up some minor issues with Windows->Linux remote.
  • Loading branch information
AWoloszyn committed Jul 31, 2018
1 parent 751cc96 commit a504c4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
19 changes: 16 additions & 3 deletions core/os/device/remotessh/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net"
"os"
"path"
"runtime"
"strings"
"sync"

Expand Down Expand Up @@ -185,8 +186,16 @@ func (b binding) PushFile(ctx context.Context, source, dest string) error {
if err != nil {
return err
}
mode := permission.Mode()
// If we are on windows pushing to Linux, we lose the executable
// bit, get it back.
if (b.os == device.Linux ||
b.os == device.OSX) &&
runtime.GOOS == "windows" {
mode |= 0550
}

return b.WriteFile(ctx, infile, permission.Mode(), dest)
return b.WriteFile(ctx, infile, mode, dest)
}

// doTunnel tunnels a single connection through the SSH connection.
Expand Down Expand Up @@ -287,7 +296,7 @@ func (b binding) GetEnv(ctx context.Context) (*shell.Env, error) {
// ListExecutables returns the executables in a particular directory as given by path
func (b binding) ListExecutables(ctx context.Context, inPath string) ([]string, error) {
if inPath == "" {
inPath = "."
inPath = b.GetURIRoot()
}
files, err := b.Shell("find", `"`+inPath+`"`, "-mindepth", "1", "-maxdepth", "1", "-type", "f", "-executable", "-printf", `%f\\n`).Call(ctx)
if err != nil {
Expand All @@ -305,7 +314,7 @@ func (b binding) ListExecutables(ctx context.Context, inPath string) ([]string,
// ListDirectories returns a list of directories rooted at a particular path
func (b binding) ListDirectories(ctx context.Context, inPath string) ([]string, error) {
if inPath == "" {
inPath = "."
inPath = b.GetURIRoot()
}
dirs, err := b.Shell("find", `"`+inPath+`"`, "-mindepth", "1", "-maxdepth", "1", "-type", "d", "-printf", `%f\\n`).Call(ctx)
if err != nil {
Expand Down Expand Up @@ -346,3 +355,7 @@ func (b binding) IsDirectory(ctx context.Context, inPath string) (bool, error) {
func (b binding) GetWorkingDirectory(ctx context.Context) (string, error) {
return b.Shell("pwd").Call(ctx)
}

func (b binding) GetURIRoot() string {
return "/"
}
11 changes: 10 additions & 1 deletion core/os/device/remotessh/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/golang/protobuf/jsonpb"
"github.com/google/gapid/core/app/layout"
"github.com/google/gapid/core/log"
"github.com/google/gapid/core/os/device"
"github.com/google/gapid/core/os/device/bind"
"github.com/google/gapid/core/os/shell"
Expand Down Expand Up @@ -196,12 +197,20 @@ func GetConnectedDevice(ctx context.Context, c Configuration) (Device, error) {
return nil, err
}

devInfo, err := b.Shell("./device-info").In(dir).Call(ctx)
stderr := bytes.Buffer{}
stdout := bytes.Buffer{}

err = b.Shell("./device-info").In(dir).Capture(&stdout, &stderr).Run(ctx)

if err != nil {
return nil, err
}

if stderr.String() != "" {
log.W(ctx, "Deviceinfo succeeded, but returned error string %s", stderr.String())
}
devInfo := stdout.String()

var device device.Instance

if err := jsonpb.Unmarshal(bytes.NewReader([]byte(devInfo)), &device); err != nil {
Expand Down

0 comments on commit a504c4b

Please sign in to comment.