From d0f447a26296a3a55107b1ec4dc71e21e3a851b0 Mon Sep 17 00:00:00 2001 From: nexustar Date: Mon, 6 Sep 2021 18:46:41 +0800 Subject: [PATCH 1/2] support start playground offline when specify version --- pkg/repository/v1_repository.go | 49 ++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/pkg/repository/v1_repository.go b/pkg/repository/v1_repository.go index 656493b4de..32310d5c3e 100644 --- a/pkg/repository/v1_repository.go +++ b/pkg/repository/v1_repository.go @@ -729,6 +729,31 @@ func (r *V1Repository) FetchComponentManifest(id string, withYanked bool) (com * return r.updateComponentManifest(id, withYanked) } +// LocalComponentManifest load the component manifest from local. +func (r *V1Repository) LocalComponentManifest(id string, withYanked bool) (com *v1manifest.Component, err error) { + index := v1manifest.Index{} + _, exists, err := r.Local().LoadManifest(&index) + if err != nil { + return nil, err + } + if !exists { + err = r.ensureManifests() + if err != nil { + return nil, err + } + _, _, err := r.Local().LoadManifest(&index) + + if err != nil { + return nil, err + } + } + + components := index.ComponentList() + comp := components[id] + filename := v1manifest.ComponentManifestFilename(id) + return r.Local().LoadComponentManifest(&comp, filename) +} + // ComponentVersion returns version item of a component func (r *V1Repository) ComponentVersion(id, ver string, includeYanked bool) (*v1manifest.VersionItem, error) { manifest, err := r.FetchComponentManifest(id, includeYanked) @@ -758,27 +783,7 @@ func (r *V1Repository) ComponentVersion(id, ver string, includeYanked bool) (*v1 // LocalComponentVersion returns version item of a component from local manifest file func (r *V1Repository) LocalComponentVersion(id, ver string, includeYanked bool) (*v1manifest.VersionItem, error) { - index := v1manifest.Index{} - _, exists, err := r.Local().LoadManifest(&index) - if err != nil { - return nil, err - } - if !exists { - err = r.ensureManifests() - if err != nil { - return nil, err - } - _, _, err := r.Local().LoadManifest(&index) - - if err != nil { - return nil, err - } - } - - components := index.ComponentList() - comp := components[id] - filename := v1manifest.ComponentManifestFilename(id) - manifest, err := r.Local().LoadComponentManifest(&comp, filename) + manifest, err := r.LocalComponentManifest(id, includeYanked) if err != nil { return nil, err } @@ -806,7 +811,7 @@ func (r *V1Repository) LocalComponentVersion(id, ver string, includeYanked bool) // ResolveComponentVersionWithPlatform resolves the latest version of a component that satisfies the constraint func (r *V1Repository) ResolveComponentVersionWithPlatform(id, constraint, platform string) (utils.Version, error) { - manifest, err := r.FetchComponentManifest(id, false) + manifest, err := r.LocalComponentManifest(id, false) if err != nil { return "", err } From e431efeb6cee571a3345dffa6f7cc5a17b2e7f46 Mon Sep 17 00:00:00 2001 From: nexustar Date: Tue, 7 Sep 2021 02:02:56 +0800 Subject: [PATCH 2/2] support tiup list --installed without network --- cmd/list.go | 14 ++++++++++---- pkg/repository/v1_repository.go | 10 +--------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cmd/list.go b/cmd/list.go index 0fece7bcdd..140d2303ca 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -91,9 +91,11 @@ func (lr *listResult) print() { } func showComponentList(env *environment.Environment, opt listOptions) (*listResult, error) { - err := env.V1Repository().UpdateComponentManifests() - if err != nil { - tui.ColorWarningMsg.Fprint(os.Stderr, "Warn: Update component manifest failed, err_msg=[", err.Error(), "]\n") + if !opt.installedOnly { + err := env.V1Repository().UpdateComponentManifests() + if err != nil { + tui.ColorWarningMsg.Fprint(os.Stderr, "Warn: Update component manifest failed, err_msg=[", err.Error(), "]\n") + } } installed, err := env.Profile().InstalledComponents() @@ -183,7 +185,11 @@ func showComponentList(env *environment.Environment, opt listOptions) (*listResu func showComponentVersions(env *environment.Environment, component string, opt listOptions) (*listResult, error) { var comp *v1manifest.Component var err error - comp, err = env.V1Repository().FetchComponentManifest(component, false) + if opt.installedOnly { + comp, err = env.V1Repository().LocalComponentManifest(component, false) + } else { + comp, err = env.V1Repository().FetchComponentManifest(component, false) + } if err != nil { return nil, errors.Annotate(err, "failed to fetch component") } diff --git a/pkg/repository/v1_repository.go b/pkg/repository/v1_repository.go index 32310d5c3e..827dc7bbb1 100644 --- a/pkg/repository/v1_repository.go +++ b/pkg/repository/v1_repository.go @@ -737,15 +737,7 @@ func (r *V1Repository) LocalComponentManifest(id string, withYanked bool) (com * return nil, err } if !exists { - err = r.ensureManifests() - if err != nil { - return nil, err - } - _, _, err := r.Local().LoadManifest(&index) - - if err != nil { - return nil, err - } + return r.FetchComponentManifest(id, withYanked) } components := index.ComponentList()