Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
22 changes: 11 additions & 11 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ func (lr *listResult) print() {
}

func showComponentList(env *environment.Environment, opt listOptions) (*listResult, error) {
if !opt.installedOnly {
// Skip online update in packaged builds
if !opt.installedOnly && !environment.IsPackagedBuild {
err := env.V1Repository().UpdateComponentManifests()
if err != nil {
tui.ColorWarningMsg.Fprint(os.Stderr, "Warn: Update component manifest failed, err_msg=[", err.Error(), "]\n")
Expand Down Expand Up @@ -182,8 +183,16 @@ func showComponentList(env *environment.Environment, opt listOptions) (*listResu
}

func showComponentVersions(env *environment.Environment, component string, opt listOptions) (*listResult, error) {
versions, err := env.Profile().InstalledVersions(component)
if err != nil {
return nil, err
}
installed := set.NewStringSet(versions...)

var cmpTable [][]string
cmpTable = append(cmpTable, []string{"Version", "Installed", "Release", "Platforms"})

var comp *v1manifest.Component
var err error
if opt.installedOnly {
comp, err = env.V1Repository().LocalComponentManifest(component, false)
} else {
Expand All @@ -193,15 +202,6 @@ func showComponentVersions(env *environment.Environment, component string, opt l
return nil, errors.Annotate(err, "failed to fetch component")
}

versions, err := env.Profile().InstalledVersions(component)
if err != nil {
return nil, err
}
installed := set.NewStringSet(versions...)

var cmpTable [][]string
cmpTable = append(cmpTable, []string{"Version", "Installed", "Release", "Platforms"})

platforms := make(map[string][]string)
released := make(map[string]string)

Expand Down
14 changes: 14 additions & 0 deletions pkg/environment/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import (
var (
// ErrInstallFirst indicates that a component/version is not installed
ErrInstallFirst = errors.New("component not installed")

// IsPackagedBuild is hard-coded to 'true' in binaries produced by packaged builds
// (e.g., Debian, RPM, Homebrew) to change their behavior to be more like real system programs.
IsPackagedBuild = true
)

// Mirror return mirror of tiup.
Expand Down Expand Up @@ -81,6 +85,13 @@ func InitEnv(options repository.Options, mOpt repository.MirrorOptions) (*Enviro
return env, nil
}

// Always initialize the repository. In packaged builds,
// specific functions (like automatic updates) will check IsPackagedBuild
// and adapt their behavior. Explicit install/list should work.
if IsPackagedBuild {
fmt.Fprintln(os.Stderr, "Online version check and repository interaction skipped in packaged build.")
}

initRepo := time.Now()
profile := localdata.InitProfile()

Expand Down Expand Up @@ -148,6 +159,9 @@ func (env *Environment) UpdateComponents(specs []string, nightly, force bool) er

// SelfUpdate updates TiUP.
func (env *Environment) SelfUpdate() error {
if IsPackagedBuild {
return errors.New("tiup self-update is disabled in this packaged build")
}
if err := env.v1Repo.DownloadTiUP(env.LocalPath("bin")); err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/exec/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ func PrepareCommand(p *PrepareCommandParams) (*exec.Cmd, error) {
}

func cmdCheckUpdate(component string, version utils.Version) {
// Skip online check in binaries installed by a package manager
if environment.IsPackagedBuild {
return
}

const (
slowTimeout = 1 * time.Second // Timeout to display checking message
cancelTimeout = 2 * time.Second // Timeout to cancel the check
Expand Down
5 changes: 5 additions & 0 deletions pkg/repository/v1_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,11 @@ func (r *V1Repository) PurgeTimestamp() {
// has the same value of our local one. (not hashing the snapshot file itself)
// Return weather the manifest is changed compared to the one in local ts and the FileHash of snapshot.
func (r *V1Repository) fetchTimestamp() (changed bool, manifest *v1manifest.Manifest, err error) {
// Ideally a repository check was not mandatory to simply run a program, but as it is,
// an uninitialized repository would cause a nil pointer dereference, so return an error.
if r == nil {
return false, nil, errors.New("repo is nil")
}
// check cache first
if r.timestamp != nil {
return false, r.timestamp, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/repository/v1manifest/local_manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@
file, err := os.Open(fullPath)
if err != nil {
if os.IsNotExist(err) {
// Use the hardcode root.json if there is no root.json currently
// Use system root.json if none was found in the local profile directory
if filename == ManifestFilenameRoot {
initRoot, err := filepath.Abs(filepath.Join(ms.profile.Root(), "bin/root.json"))
initRoot, err := filepath.Abs(filepath.Join("/usr/share/tiup/root.json"))

Check failure on line 203 in pkg/repository/v1manifest/local_manifests.go

View workflow job for this annotation

GitHub Actions / unit-test

badCall: suspicious Join on 1 argument (gocritic)
if err != nil {
return "", errors.Trace(err)
}
Expand Down
Loading