diff --git a/executable.go b/executable.go new file mode 100644 index 0000000..1794e94 --- /dev/null +++ b/executable.go @@ -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) +} diff --git a/executable_unix.go b/executable_unix.go new file mode 100644 index 0000000..d1b947c --- /dev/null +++ b/executable_unix.go @@ -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) +} diff --git a/executable_win.go b/executable_win.go new file mode 100644 index 0000000..4652eca --- /dev/null +++ b/executable_win.go @@ -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") +} diff --git a/server.go b/server.go index f5a91e7..6b6d135 100644 --- a/server.go +++ b/server.go @@ -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 isExecutable(path) }, CmdCombinedOutput: func(name string, arg ...string) ([]byte, error) { return exec.Command(name, arg...).CombinedOutput()