Skip to content

Commit

Permalink
goversion: use file extension to test for executables on Windows
Browse files Browse the repository at this point in the history
Fixes #2.
  • Loading branch information
rsc committed Apr 3, 2018
1 parent bbd79cf commit e2aeda8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion main.go
Expand Up @@ -57,6 +57,7 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"strings"
"unicode/utf8"

Expand Down Expand Up @@ -112,6 +113,13 @@ func scandir(dir string) {
})
}

func isExe(file string, info os.FileInfo) bool {
if runtime.GOOS == "windows" {
return strings.HasSuffix(strings.ToLower(file), ".exe")
}
return info.Mode()&0111 != 0
}

func scanfile(file, diskFile string, info os.FileInfo, mustPrint bool) {
if strings.HasSuffix(file, ".tar") {
if file != diskFile {
Expand Down Expand Up @@ -146,7 +154,7 @@ func scanfile(file, diskFile string, info os.FileInfo, mustPrint bool) {
}
info = i
}
if file == diskFile && info.Mode()&0111 == 0 {
if file == diskFile && !isExe(file, info) {
if mustPrint {
fmt.Fprintf(os.Stderr, "%s: not executable\n", file)
}
Expand Down

0 comments on commit e2aeda8

Please sign in to comment.