update: For source builds look for absolute path. (#3780)

os.Args[0] doesn't point to absolute path we need
use exec.LookPath to find the absolute path before
sending os.Stat().
This commit is contained in:
Harshavardhana
2017-02-21 01:32:05 -08:00
committed by GitHub
parent 097dd7418a
commit 99a12613a3
6 changed files with 72 additions and 24 deletions

View File

@@ -22,6 +22,8 @@ import (
"io/ioutil"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"
@@ -62,15 +64,24 @@ EXAMPLES:
`,
}
const releaseTagTimeLayout = "2006-01-02T15-04-05Z"
const minioReleaseURL = "https://dl.minio.io/server/minio/release/" + runtime.GOOS + "-" + runtime.GOARCH + "/"
const (
minioReleaseTagTimeLayout = "2006-01-02T15-04-05Z"
minioReleaseURL = "https://dl.minio.io/server/minio/release/" + runtime.GOOS + "-" + runtime.GOARCH + "/"
)
func getCurrentReleaseTime(minioVersion, minioBinaryPath string) (releaseTime time.Time, err error) {
if releaseTime, err = time.Parse(time.RFC3339, minioVersion); err == nil {
return releaseTime, err
}
if !filepath.IsAbs(minioBinaryPath) {
// Make sure to look for the absolute path of the binary.
minioBinaryPath, err = exec.LookPath(minioBinaryPath)
if err != nil {
return releaseTime, err
}
}
// Looks like version is minio non-standard, we use minio binary's ModTime as release time.
fi, err := os.Stat(minioBinaryPath)
if err != nil {
@@ -190,7 +201,7 @@ func parseReleaseData(data string) (releaseTime time.Time, err error) {
return releaseTime, err
}
releaseTime, err = time.Parse(releaseTagTimeLayout, fields[2])
releaseTime, err = time.Parse(minioReleaseTagTimeLayout, fields[2])
if err != nil {
err = fmt.Errorf("Unknown release time format. %s", err)
}