Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TiUP: update --self add some checks. #1695

Merged
merged 8 commits into from
Dec 28, 2021
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cmd
import (
"fmt"
"os"
"path/filepath"

"github.com/pingcap/tiup/pkg/environment"
"github.com/pingcap/tiup/pkg/utils"
Expand Down Expand Up @@ -47,6 +48,10 @@ latest version. All other flags will be ignored if the flag --self is given.

env := environment.GlobalEnv()
if self {
if err := checkTiUPBinary(env); err != nil {
return err
}

originFile := env.LocalPath("bin", "tiup")
renameFile := env.LocalPath("bin", "tiup.tmp")
if err := os.Rename(originFile, renameFile); err != nil {
Expand Down Expand Up @@ -100,3 +105,22 @@ func updateComponents(env *environment.Environment, components []string, nightly

return env.UpdateComponents(components, nightly, force)
}

// checkTiUPBinary check if TiUP exists in TiUP_HOME
func checkTiUPBinary(env *environment.Environment) error {
tiUPHomePath, _ := filepath.Abs(env.LocalPath("bin", "tiup"))

realTiUPPath, err := os.Executable()
if err != nil {
// Ignore the problem that the execution directory cannot be obtained
return nil
}
realTiUPPath, _ = filepath.Abs(realTiUPPath)

if utils.IsNotExist(tiUPHomePath) || tiUPHomePath != realTiUPPath {
fmt.Printf("Tiup install directory is: %s\n", filepath.Dir(realTiUPPath))
return fmt.Errorf("If you used some external package manager to install TiUP (e.g., brew), try upgrade with that")
}

return nil
}