refactor code
This commit is contained in:
parent
daaa0fa467
commit
5d71bb68b4
|
@ -4,6 +4,6 @@ package adb
|
||||||
|
|
||||||
import "golang.org/x/sys/unix"
|
import "golang.org/x/sys/unix"
|
||||||
|
|
||||||
func access(path string) error {
|
func isExecutableOnPlatform(path string) error {
|
||||||
return unix.Access(path, unix.X_OK)
|
return unix.Access(path, unix.X_OK)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func access(path string) error {
|
func isExecutableOnPlatform(path string) error {
|
||||||
if strings.Contains(path, ".exe") {
|
if strings.HasSuffix(path, ".exe") || strings.HasSuffix(path, ".cmd") ||
|
||||||
|
strings.HasSuffix(path, ".bat") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return errors.New("not an executable")
|
return errors.New("not an executable")
|
||||||
|
|
|
@ -136,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 Access(path)
|
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()
|
||||||
|
|
12
unix.go
12
unix.go
|
@ -1,11 +1,11 @@
|
||||||
package adb
|
package adb
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Exported Access function calls private access function.
|
isExecutable function calls the isExecutableOnPlatform function.
|
||||||
Implementation for private access function is provided in
|
Implementation the isExecutableOnPlatform function is provided in
|
||||||
access_win.go for windows and
|
execuatble_win.go for windows and
|
||||||
access_unix.go for unix
|
executable_unix.go for unix.
|
||||||
*/
|
*/
|
||||||
func Access(path string) error {
|
func isExecutable(path string) error {
|
||||||
return access(path)
|
return isExecutableOnPlatform(path)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue