From b87cc3d643df8ebd0033af7a3ec9df2d8a09e3ad Mon Sep 17 00:00:00 2001 From: kannappanr <30541348+kannappanr@users.noreply.github.com> Date: Fri, 30 Mar 2018 19:13:25 -0700 Subject: [PATCH] Get proper GOPATH in trim function (#5744) Set GOPATH string to empty in build-constants.go Check for both compile time GOPATH and default GOPATH while trimming the file path in the stack trace. Fixes #5741 --- cmd/build-constants.go | 4 +--- cmd/logger.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/build-constants.go b/cmd/build-constants.go index 36fca9299..ff2a55f57 100644 --- a/cmd/build-constants.go +++ b/cmd/build-constants.go @@ -16,13 +16,11 @@ package cmd -import "go/build" - // DO NOT EDIT THIS FILE DIRECTLY. These are build-time constants // set through ‘buildscripts/gen-ldflags.go’. var ( // GOPATH - GOPATH value at the time of build. - GOPATH = build.Default.GOPATH + GOPATH = "" // Go get development tag. goGetTag = "DEVELOPMENT.GOGET" diff --git a/cmd/logger.go b/cmd/logger.go index 5cba94fcb..390124149 100644 --- a/cmd/logger.go +++ b/cmd/logger.go @@ -19,6 +19,7 @@ package cmd import ( "encoding/json" "fmt" + "go/build" "os" "path/filepath" "runtime" @@ -98,13 +99,17 @@ func (log *Logger) Printf(format string, args ...interface{}) { func init() { var goPathList []string + var defaultgoPathList []string // Add all possible GOPATH paths into trimStrings // Split GOPATH depending on the OS type if runtime.GOOS == "windows" { goPathList = strings.Split(GOPATH, ";") + defaultgoPathList = strings.Split(build.Default.GOPATH, ";") } else { // All other types of OSs goPathList = strings.Split(GOPATH, ":") + defaultgoPathList = strings.Split(build.Default.GOPATH, ":") + } // Add trim string "{GOROOT}/src/" into trimStrings @@ -115,6 +120,11 @@ func init() { for _, goPathString := range goPathList { trimStrings = append(trimStrings, filepath.Join(goPathString, "src")+string(filepath.Separator)) } + + for _, defaultgoPathString := range defaultgoPathList { + trimStrings = append(trimStrings, filepath.Join(defaultgoPathString, "src")+string(filepath.Separator)) + } + // Add "github.com/minio/minio" as the last to cover // paths like "{GOROOT}/src/github.com/minio/minio" // and "{GOPATH}/src/github.com/minio/minio"