ccollins476ad closed pull request #132: Newt - Don't display warning on initial install. URL: https://github.com/apache/mynewt-newt/pull/132
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/newt/interfaces/interfaces.go b/newt/interfaces/interfaces.go index 12826d02..cfbbbe64 100644 --- a/newt/interfaces/interfaces.go +++ b/newt/interfaces/interfaces.go @@ -66,6 +66,7 @@ type ProjectInterface interface { ResolvePath(basePath string, name string) (string, error) PackageList() PackageList FindRepoPath(rname string) string + RepoIsInstalled(rname string) bool } var globalProject ProjectInterface diff --git a/newt/project/project.go b/newt/project/project.go index 6bfdb9a0..cdd0b84f 100644 --- a/newt/project/project.go +++ b/newt/project/project.go @@ -185,6 +185,11 @@ func (proj *Project) FindRepoPath(rname string) string { return r.Path() } +// Indicates whether the specified repo is present in the `project.state` file. +func (proj *Project) RepoIsInstalled(rname string) bool { + return proj.projState.GetInstalledVersion(rname) != nil +} + func (proj *Project) LocalRepo() *repo.Repo { return proj.localRepo } diff --git a/newt/repo/repo.go b/newt/repo/repo.go index 8eb8844a..760cd756 100644 --- a/newt/repo/repo.go +++ b/newt/repo/repo.go @@ -117,8 +117,15 @@ func (repo *Repo) FilteredSearchList( path := filepath.Join(repo.Path(), curPath) dirList, err := ioutil.ReadDir(path) if err != nil { - return list, util.FmtNewtError("failed to read repo \"%s\": %s", - repo.Name(), err.Error()) + // The repo could not be found in the `repos` directory. Display a + // warning if the `project.state` file indicates that the repo has been + // installed. + var warning error + if interfaces.GetProject().RepoIsInstalled(repo.Name()) { + warning = util.FmtNewtError("failed to read repo \"%s\": %s", + repo.Name(), err.Error()) + } + return list, warning } for _, dirEnt := range dirList { @@ -464,7 +471,7 @@ func (r *Repo) updateRepo(branchName string) error { dl := r.downloader err := dl.UpdateRepo(r.Path(), branchName) if err != nil { - return util.NewNewtError("Error updating\n") + return util.FmtNewtError("Error updating: %s", err.Error()) } return nil } @@ -473,7 +480,7 @@ func (r *Repo) cleanupRepo(branchName string) error { dl := r.downloader err := dl.CleanupRepo(r.Path(), branchName) if err != nil { - return util.NewNewtError("Error cleaning and updating\n") + return util.FmtNewtError("Error cleaning and updating: %s", err.Error()) } return nil } @@ -493,14 +500,14 @@ func (r *Repo) saveLocalDiff() (string, error) { f, err := os.Create(filename) if err != nil { return "", - util.FmtNewtError("Error creating repo diff file \"%s\"", filename) + util.FmtNewtError("Error creating repo diff file \"%s\": %s", filename, err.Error()) } defer f.Close() _, err = f.Write(diff) if err != nil { return "", - util.FmtNewtError("Error writing repo diff file \"%s\"", filename) + util.FmtNewtError("Error writing repo diff file \"%s\": %s", filename, err.Error()) } return filename, nil @@ -567,8 +574,8 @@ func (r *Repo) Sync(vers *Version, force bool) (bool, error) { branchName, _, found := r.rdesc.MatchVersion(vers) if found == false { - return false, util.NewNewtError(fmt.Sprintf( - "Branch description for %s not found", r.Name())) + return false, util.FmtNewtError( + "Branch description for %s not found", r.Name()) } // Here assuming that if the branch was changed by the user, @@ -642,7 +649,6 @@ func (r *Repo) UpdateDesc() ([]*Repo, bool, error) { _, repos, err := r.ReadDesc() if err != nil { - fmt.Printf("ReadDesc: %v\n", err) return nil, false, err } @@ -717,8 +723,8 @@ func (r *Repo) readDepRepos(yc ycfg.YCfg) ([]*Repo, error) { branch, _, ok := rdesc.Match(r) if !ok { // No matching branch, barf! - return nil, util.NewNewtError(fmt.Sprintf("No "+ - "matching branch for %s repo", r.Name())) + return nil, util.FmtNewtError("No "+ + "matching branch for %s repo", r.Name()) } repoTag := fmt.Sprintf("%s.repositories", branch) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services