Skip to content

Commit

Permalink
cmd/go: fix version -m not go executable file exits with status 0
Browse files Browse the repository at this point in the history
Fixes #66426

Change-Id: Ie07ab6012063c0f087fd0525812079764444f8fa
  • Loading branch information
qiulaidongfeng committed Mar 21, 2024
1 parent cff7267 commit 871b400
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/cmd/go/internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ func runVersion(ctx context.Context, cmd *base.Command, args []string) {
if info.IsDir() {
scanDir(arg)
} else {
scanFile(arg, info, true)
ok := scanFile(arg, info, true)
if !ok {
base.SetExitStatus(1)
}
}
}
}
Expand Down Expand Up @@ -132,15 +135,15 @@ func isGoBinaryCandidate(file string, info fs.FileInfo) bool {
// If mustPrint is true, scanFile will report any error reading file.
// Otherwise (mustPrint is false, because scanFile is being called
// by scanDir) scanFile prints nothing for non-Go binaries.
func scanFile(file string, info fs.FileInfo, mustPrint bool) {
func scanFile(file string, info fs.FileInfo, mustPrint bool) (ok bool) {
if info.Mode()&fs.ModeSymlink != 0 {
// Accept file symlinks only.
i, err := os.Stat(file)
if err != nil || !i.Mode().IsRegular() {
if mustPrint {
fmt.Fprintf(os.Stderr, "%s: symlink\n", file)
}
return
return false
}
info = i
}
Expand All @@ -161,7 +164,7 @@ func scanFile(file string, info fs.FileInfo, mustPrint bool) {
}
}
}
return
return false
}

fmt.Printf("%s: %s\n", file, bi.GoVersion)
Expand All @@ -170,4 +173,5 @@ func scanFile(file string, info fs.FileInfo, mustPrint bool) {
if *versionM && len(mod) > 0 {
fmt.Printf("\t%s\n", strings.ReplaceAll(mod[:len(mod)-1], "\n", "\n\t"))
}
return true
}

0 comments on commit 871b400

Please sign in to comment.