diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-12 22:40:57 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-12 22:58:01 +1100 |
commit | b907c743867dca7889e39b3e4490457ec33b0380 (patch) | |
tree | 79dbf9d88de5af1a67748d775138a26b970e021f /pkg/updates | |
parent | a68fb4fb8f7169b91f617c80deda177901c4202c (diff) |
remove go-getter
Diffstat (limited to 'pkg/updates')
-rw-r--r-- | pkg/updates/updates.go | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/pkg/updates/updates.go b/pkg/updates/updates.go index aa5b65287..ecad64d37 100644 --- a/pkg/updates/updates.go +++ b/pkg/updates/updates.go @@ -3,8 +3,8 @@ package updates import ( "encoding/json" "fmt" + "io" "net/http" - "net/url" "os" "path/filepath" "runtime" @@ -15,7 +15,6 @@ import ( "github.com/kardianos/osext" - "github.com/jesseduffield/go-getter" "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/i18n" @@ -254,17 +253,34 @@ func (u *Updater) update(newVersion string) error { } func (u *Updater) downloadAndInstall(rawUrl string) error { - url, err := url.Parse(rawUrl) + configDir := u.Config.GetUserConfigDir() + u.Log.Info("Download directory is " + configDir) + + tempPath := filepath.Join(configDir, "temp_lazygit") + u.Log.Info("Temp path to binary is " + tempPath) + + // Create the file + out, err := os.Create(tempPath) if err != nil { return err } + defer out.Close() - g := new(getter.HttpGetter) - configDir := u.Config.GetUserConfigDir() - u.Log.Info("Download directory is " + configDir) + // Get the data + resp, err := http.Get(rawUrl) + if err != nil { + return err + } + defer resp.Body.Close() + + // Check server response + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("error while trying to download latest lazygit: %s", resp.Status) + } - // Get it! - if err := g.Get(configDir, url); err != nil { + // Write the body to file + _, err = io.Copy(out, resp.Body) + if err != nil { return err } @@ -275,12 +291,7 @@ func (u *Updater) downloadAndInstall(rawUrl string) error { } u.Log.Info("Binary path is " + binaryPath) - binaryName := filepath.Base(binaryPath) - u.Log.Info("Binary name is " + binaryName) - // Verify the main file exists - tempPath := filepath.Join(configDir, binaryName) - u.Log.Info("Temp path to binary is " + tempPath) if _, err := os.Stat(tempPath); err != nil { return err } |