Pipe ctx into the Update function

This commit is contained in:
David Dworken 2022-09-21 20:20:43 -07:00
parent 8002c5e942
commit d226fab7ec
2 changed files with 3 additions and 6 deletions

View File

@ -637,7 +637,7 @@ func GetDownloadData() (shared.UpdateInfo, error) {
return downloadData, nil return downloadData, nil
} }
func Update() error { func Update(ctx *context.Context) error {
// Download the binary // Download the binary
downloadData, err := GetDownloadData() downloadData, err := GetDownloadData()
if err != nil { if err != nil {
@ -664,10 +664,7 @@ func Update() error {
// Unlink the existing binary so we can overwrite it even though it is still running // Unlink the existing binary so we can overwrite it even though it is still running
if runtime.GOOS == "linux" { if runtime.GOOS == "linux" {
homedir, err := os.UserHomeDir() homedir := hctx.GetHome(ctx)
if err != nil {
return fmt.Errorf("failed to get user's home directory: %v", err)
}
err = syscall.Unlink(path.Join(homedir, shared.HISHTORY_PATH, "hishtory")) err = syscall.Unlink(path.Join(homedir, shared.HISHTORY_PATH, "hishtory"))
if err != nil { if err != nil {
return fmt.Errorf("failed to unlink %s for update: %v", path.Join(homedir, shared.HISHTORY_PATH, "hishtory"), err) return fmt.Errorf("failed to unlink %s for update: %v", path.Join(homedir, shared.HISHTORY_PATH, "hishtory"), err)

View File

@ -90,7 +90,7 @@ func main() {
} }
fmt.Printf("Commit Hash: %s\n", GitCommit) fmt.Printf("Commit Hash: %s\n", GitCommit)
case "update": case "update":
lib.CheckFatalError(lib.Update()) lib.CheckFatalError(lib.Update(hctx.MakeContext()))
case "-h": case "-h":
fallthrough fallthrough
case "help": case "help":