mirror of
https://github.com/MedzikUser/go-github-selfupdate.git
synced 2024-08-15 03:25:29 +00:00
add more logs
This commit is contained in:
parent
fd8fc6616a
commit
0cce7553af
3 changed files with 12 additions and 1 deletions
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
func TestEnableDisableLog(t *testing.T) {
|
||||
defer EnableLog()
|
||||
defer DisableLog()
|
||||
|
||||
EnableLog()
|
||||
if !logEnabled {
|
||||
|
|
|
@ -14,6 +14,8 @@ import (
|
|||
|
||||
func uncompress(src io.Reader, url, cmd string) (io.Reader, error) {
|
||||
if strings.HasSuffix(url, ".zip") {
|
||||
log.Println("Uncompressing zip file", url)
|
||||
|
||||
// Zip format requires its file size for uncompressing.
|
||||
// So we need to read the HTTP response into a buffer at first.
|
||||
buf, err := ioutil.ReadAll(src)
|
||||
|
@ -36,6 +38,8 @@ func uncompress(src io.Reader, url, cmd string) (io.Reader, error) {
|
|||
|
||||
return nil, fmt.Errorf("File '%s' for the command is not found in %s", cmd, url)
|
||||
} else if strings.HasSuffix(url, ".tar.gz") {
|
||||
log.Println("Uncompressing tar.gz file", url)
|
||||
|
||||
gz, err := gzip.NewReader(src)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to uncompress .tar.gz file: %s", err)
|
||||
|
@ -58,6 +62,8 @@ func uncompress(src io.Reader, url, cmd string) (io.Reader, error) {
|
|||
|
||||
return nil, fmt.Errorf("File '%s' for the command is not found in %s", cmd, url)
|
||||
} else if strings.HasSuffix(url, ".gzip") || strings.HasSuffix(url, ".gz") {
|
||||
log.Println("Uncompressing gzip file", url)
|
||||
|
||||
r, err := gzip.NewReader(src)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to uncompress gzip file downloaded from %s: %s", url, err)
|
||||
|
@ -71,5 +77,6 @@ func uncompress(src io.Reader, url, cmd string) (io.Reader, error) {
|
|||
return r, nil
|
||||
}
|
||||
|
||||
log.Println("Uncompression is not needed", url)
|
||||
return src, nil
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ func UpdateTo(assetURL, cmdPath string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
log.Println("Will update", cmdPath, "to the latest downloaded from", assetURL)
|
||||
return update.Apply(asset, update.Options{
|
||||
TargetPath: cmdPath,
|
||||
})
|
||||
|
@ -40,11 +41,14 @@ func UpdateCommand(cmdPath string, current semver.Version, slug string) (*Releas
|
|||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
log.Println("No release detected. Current version is considered up-to-date")
|
||||
return &Release{Version: current}, nil
|
||||
}
|
||||
if current.Equals(rel.Version) {
|
||||
log.Println("Current version", current, "is the latest. Update is not needed")
|
||||
return rel, nil
|
||||
}
|
||||
log.Println("Will update", cmdPath, "to the latest version", rel.Version)
|
||||
if err := UpdateTo(rel.AssetURL, cmdPath); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue