Skip to content

Commit

Permalink
Fix content type of auto upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanwichmann committed Mar 18, 2017
1 parent 946d84c commit 8f7c93a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 7 additions & 5 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"errors"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"runtime"
Expand All @@ -51,12 +50,15 @@ func downloadLatestReleaseInfo(url string) (releaseName string, assetUrl string,
return "", "", err
}

log.Printf("Github data: %v\n", data)
releaseInfo := data.(map[string]interface{})
if releaseInfo["name"] == nil {
var name string
if releaseInfo["name"] != nil {
name = releaseInfo["name"].(string)
} else if releaseInfo["tag_name"] != nil {
name = releaseInfo["tag_name"].(string)
} else {
return "", "", errors.New("No releases available")
}
name := releaseInfo["name"].(string)

releaseAssets := releaseInfo["assets"].([]interface{})
for _, asset := range releaseAssets {
Expand All @@ -74,7 +76,7 @@ func downloadLatestReleaseInfo(url string) (releaseName string, assetUrl string,
func assetMatchesPlattform(asset map[string]interface{}) (bool, string) {
// match content type
contentType := asset["content_type"].(string)
if !strings.Contains(contentType, "application/octet-stream") {
if !strings.Contains(contentType, "application/gzip") {
return false, ""
}

Expand Down
3 changes: 1 addition & 2 deletions upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ func CheckForUpdate(currentVersion string) {
}

if !avail {
log.Printf("No new version available.\n")
time.Sleep(updateCheckIntervalInMinutes * time.Minute)
} else {
log.Printf("Update available: %v\n", url)
err = updateBinary(url)
if err != nil {
log.Printf("Error updating binary: %v.\n", err)
Expand Down Expand Up @@ -92,6 +90,7 @@ func updateAvailable(currentVersion *version.Version, url string) (bool, error,
}

if version.GreaterThan(currentVersion) {
log.Printf("Found new release version %s.", version)
return true, nil, assetUrl
}

Expand Down

0 comments on commit 8f7c93a

Please sign in to comment.