binary-update: Do not fetch update info for minio binary compiled from source.

fixes #2494
This commit is contained in:
Krishna Srinivas 2016-08-19 20:39:05 +05:30 committed by Harshavardhana
parent b4e4846e9f
commit 81d8263ae2
2 changed files with 48 additions and 45 deletions

View File

@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"os" "os"
"sort" "sort"
"strings"
"github.com/minio/cli" "github.com/minio/cli"
"github.com/minio/mc/pkg/console" "github.com/minio/mc/pkg/console"
@ -180,14 +181,16 @@ func Main() {
// Do not print update messages, if quiet flag is set. // Do not print update messages, if quiet flag is set.
if !globalQuiet { if !globalQuiet {
// Do not print any errors in release update function. if strings.HasPrefix(Version, "RELEASE.") {
noError := true updateMsg, _, err := getReleaseUpdate(minioUpdateStableURL)
updateMsg := getReleaseUpdate(minioUpdateStableURL, noError) if err != nil {
if updateMsg.Update { // Ignore any errors during getReleaseUpdate() because
// the internet might not be available.
return nil
}
console.Println(updateMsg) console.Println(updateMsg)
} }
} }
return nil return nil
} }

View File

@ -129,7 +129,7 @@ func parseReleaseData(data string) (time.Time, error) {
} }
// verify updates for releases. // verify updates for releases.
func getReleaseUpdate(updateURL string, noError bool) updateMessage { func getReleaseUpdate(updateURL string) (updateMsg updateMessage, errMsg string, err error) {
// Construct a new update url. // Construct a new update url.
newUpdateURLPrefix := updateURL + "/" + runtime.GOOS + "-" + runtime.GOARCH newUpdateURLPrefix := updateURL + "/" + runtime.GOOS + "-" + runtime.GOARCH
newUpdateURL := newUpdateURLPrefix + "/minio.shasum" newUpdateURL := newUpdateURLPrefix + "/minio.shasum"
@ -146,7 +146,7 @@ func getReleaseUpdate(updateURL string, noError bool) updateMessage {
} }
// Initialize update message. // Initialize update message.
updateMsg := updateMessage{ updateMsg = updateMessage{
Download: downloadURL, Download: downloadURL,
Version: Version, Version: Version,
} }
@ -156,61 +156,54 @@ func getReleaseUpdate(updateURL string, noError bool) updateMessage {
Timeout: 3 * time.Second, Timeout: 3 * time.Second,
} }
// Fetch new update.
data, err := client.Get(newUpdateURL)
if err != nil && noError {
return updateMsg
}
fatalIf((err), "Unable to read from update URL "+newUpdateURL+".")
// Error out if 'update' command is issued for development based builds.
if Version == "DEVELOPMENT.GOGET" && !noError {
fatalIf((errors.New("")),
"Update mechanism is not supported for go get based binary builds. Please download official releases from https://minio.io/#minio")
}
// Parse current minio version into RFC3339. // Parse current minio version into RFC3339.
current, err := time.Parse(time.RFC3339, Version) current, err := time.Parse(time.RFC3339, Version)
if err != nil && noError { if err != nil {
return updateMsg errMsg = "Unable to parse version string as time."
return
} }
fatalIf((err), "Unable to parse version string as time.")
// Verify if current minio version is zero. // Verify if current minio version is zero.
if current.IsZero() && !noError { if current.IsZero() {
fatalIf((errors.New("")), err = errors.New("date should not be zero")
"Updates mechanism is not supported for custom builds. Please download official releases from https://minio.io/#minio") errMsg = "Updates mechanism is not supported for custom builds. Please download official releases from https://minio.io/#minio"
return
}
// Fetch new update.
data, err := client.Get(newUpdateURL)
if err != nil {
return
} }
// Verify if we have a valid http response i.e http.StatusOK. // Verify if we have a valid http response i.e http.StatusOK.
if data != nil { if data != nil {
if data.StatusCode != http.StatusOK { if data.StatusCode != http.StatusOK {
// Return quickly if noError is set. errMsg = "Failed to retrieve update notice."
if noError { err = errors.New("http status : " + data.Status)
return updateMsg return
}
fatalIf((errors.New("")), "Failed to retrieve update notice. "+data.Status)
} }
} }
// Read the response body. // Read the response body.
updateBody, err := ioutil.ReadAll(data.Body) updateBody, err := ioutil.ReadAll(data.Body)
if err != nil && noError { if err != nil {
return updateMsg errMsg = "Failed to retrieve update notice. Please try again later."
return
} }
fatalIf((err), "Failed to retrieve update notice. Please try again later.")
errMsg = "Failed to retrieve update notice. Please try again later. Please report this issue at https://github.com/minio/minio/issues"
// Parse the date if its valid. // Parse the date if its valid.
latest, err := parseReleaseData(string(updateBody)) latest, err := parseReleaseData(string(updateBody))
if err != nil && noError { if err != nil {
return updateMsg return
} }
errMsg := "Failed to retrieve update notice. Please try again later. Please report this issue at https://github.com/minio/minio/issues"
fatalIf(err, errMsg)
// Verify if the date is not zero. // Verify if the date is not zero.
if latest.IsZero() && !noError { if latest.IsZero() {
fatalIf((errors.New("")), errMsg) err = errors.New("date should not be zero")
return
} }
// Is the update latest?. // Is the update latest?.
@ -219,18 +212,25 @@ func getReleaseUpdate(updateURL string, noError bool) updateMessage {
} }
// Return update message. // Return update message.
return updateMsg return updateMsg, "", nil
} }
// main entry point for update command. // main entry point for update command.
func mainUpdate(ctx *cli.Context) { func mainUpdate(ctx *cli.Context) {
// Print all errors as they occur. // Error out if 'update' command is issued for development based builds.
noError := false if Version == "DEVELOPMENT.GOGET" {
fatalIf(errors.New(""), "Update mechanism is not supported for go get based binary builds. Please download official releases from https://minio.io/#minio")
}
// Check for update. // Check for update.
var updateMsg updateMessage
var errMsg string
var err error
if ctx.Bool("experimental") { if ctx.Bool("experimental") {
console.Println(getReleaseUpdate(minioUpdateExperimentalURL, noError)) updateMsg, errMsg, err = getReleaseUpdate(minioUpdateExperimentalURL)
} else { } else {
console.Println(getReleaseUpdate(minioUpdateStableURL, noError)) updateMsg, errMsg, err = getReleaseUpdate(minioUpdateStableURL)
} }
fatalIf(err, errMsg)
console.Println(updateMsg)
} }