Merge pull request #23 from mandarl/master
Add conditional build files for unix.Access.
This commit is contained in:
commit
6cf99d9b4a
11
executable.go
Normal file
11
executable.go
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package adb
|
||||||
|
|
||||||
|
/*
|
||||||
|
isExecutable function calls the isExecutableOnPlatform function.
|
||||||
|
Implementation the isExecutableOnPlatform function is provided in
|
||||||
|
execuatble_win.go for windows and
|
||||||
|
executable_unix.go for unix.
|
||||||
|
*/
|
||||||
|
func isExecutable(path string) error {
|
||||||
|
return isExecutableOnPlatform(path)
|
||||||
|
}
|
9
executable_unix.go
Normal file
9
executable_unix.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// +build darwin freebsd linux netbsd openbsd
|
||||||
|
|
||||||
|
package adb
|
||||||
|
|
||||||
|
import "golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
func isExecutableOnPlatform(path string) error {
|
||||||
|
return unix.Access(path, unix.X_OK)
|
||||||
|
}
|
16
executable_win.go
Normal file
16
executable_win.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package adb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func isExecutableOnPlatform(path string) error {
|
||||||
|
if strings.HasSuffix(path, ".exe") || strings.HasSuffix(path, ".cmd") ||
|
||||||
|
strings.HasSuffix(path, ".bat") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return errors.New("not an executable")
|
||||||
|
}
|
|
@ -9,7 +9,6 @@ import (
|
||||||
|
|
||||||
"github.com/zach-klippenstein/goadb/internal/errors"
|
"github.com/zach-klippenstein/goadb/internal/errors"
|
||||||
"github.com/zach-klippenstein/goadb/wire"
|
"github.com/zach-klippenstein/goadb/wire"
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -137,7 +136,7 @@ var localFilesystem = &filesystem{
|
||||||
if !info.Mode().IsRegular() {
|
if !info.Mode().IsRegular() {
|
||||||
return stderrors.New("not a regular file")
|
return stderrors.New("not a regular file")
|
||||||
}
|
}
|
||||||
return unix.Access(path, unix.X_OK)
|
return isExecutable(path)
|
||||||
},
|
},
|
||||||
CmdCombinedOutput: func(name string, arg ...string) ([]byte, error) {
|
CmdCombinedOutput: func(name string, arg ...string) ([]byte, error) {
|
||||||
return exec.Command(name, arg...).CombinedOutput()
|
return exec.Command(name, arg...).CombinedOutput()
|
||||||
|
|
Loading…
Reference in a new issue