Add conditional build files for unix.Access.

This will allow library to be built on windows.
This commit is contained in:
Mandar Limaye 2016-08-09 12:07:21 -05:00
parent e87d5c6814
commit daaa0fa467
4 changed files with 36 additions and 2 deletions

9
access_unix.go Normal file
View file

@ -0,0 +1,9 @@
// +build darwin freebsd linux netbsd openbsd
package adb
import "golang.org/x/sys/unix"
func access(path string) error {
return unix.Access(path, unix.X_OK)
}

15
access_win.go Normal file
View file

@ -0,0 +1,15 @@
// +build windows
package adb
import (
"errors"
"strings"
)
func access(path string) error {
if strings.Contains(path, ".exe") {
return nil
}
return errors.New("not an executable")
}

View file

@ -9,7 +9,6 @@ import (
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
"golang.org/x/sys/unix"
)
const (
@ -137,7 +136,7 @@ var localFilesystem = &filesystem{
if !info.Mode().IsRegular() {
return stderrors.New("not a regular file")
}
return unix.Access(path, unix.X_OK)
return Access(path)
},
CmdCombinedOutput: func(name string, arg ...string) ([]byte, error) {
return exec.Command(name, arg...).CombinedOutput()

11
unix.go Normal file
View file

@ -0,0 +1,11 @@
package adb
/*
Exported Access function calls private access function.
Implementation for private access function is provided in
access_win.go for windows and
access_unix.go for unix
*/
func Access(path string) error {
return access(path)
}