func (proj *Project) checkDeps(r *repo.Repo) error { repos, updated, err := r.UpdateDesc() if err != nil { return err } if !updated { return nil } for _, newRepo := range repos { curRepo, ok := proj.repos[newRepo.Name()] if !ok { proj.repos[newRepo.Name()] = newRepo return proj.UpdateRepos() } else { // Add any dependencies we might have found here. for _, dep := range newRepo.Deps() { newRepo.DownloadDesc() newRepo.ReadDesc() curRepo.AddDependency(dep) } } } return nil }
func ReadLocalPackageRecursive(repo *repo.Repo, pkgList map[string]interfaces.PackageInterface, basePath string, pkgName string) ([]string, error) { var warnings []string dirList, err := repo.FilteredSearchList(pkgName) if err != nil { return warnings, util.NewNewtError(err.Error()) } for _, name := range dirList { if LocalPackageSpecialName(name) || strings.HasPrefix(name, ".") { continue } subWarnings, err := ReadLocalPackageRecursive(repo, pkgList, basePath, filepath.Join(pkgName, name)) warnings = append(warnings, subWarnings...) if err != nil { return warnings, err } } if util.NodeNotExist(filepath.Join(basePath, pkgName, PACKAGE_FILE_NAME)) { return warnings, nil } pkg, err := LoadLocalPackage(repo, filepath.Join(basePath, pkgName)) if err != nil { warnings = append(warnings, err.Error()) return warnings, nil } if oldPkg, ok := pkgList[pkg.Name()]; ok { oldlPkg := oldPkg.(*LocalPackage) warnings = append(warnings, fmt.Sprintf("Multiple packages with same pkg.name=%s "+ "in repo %s; path1=%s path2=%s", oldlPkg.Name(), repo.Name(), oldlPkg.BasePath(), pkg.BasePath())) return warnings, nil } pkgList[pkg.Name()] = pkg return warnings, nil }
func (pkg *LocalPackage) Clone(newRepo *repo.Repo, newName string) *LocalPackage { // XXX: Validate name. // Copy the package. newPkg := *pkg newPkg.repo = newRepo newPkg.name = newName newPkg.basePath = newRepo.Path() + "/" + newPkg.name // Insert the clone into the global package map. proj := interfaces.GetProject() pMap := proj.PackageList() (*pMap[newRepo.Name()])[newPkg.name] = &newPkg return &newPkg }
func (proj *Project) checkVersionRequirements(r *repo.Repo, upgrade bool, force bool) (bool, error) { rdesc, err := r.GetRepoDesc() if err != nil { return false, err } rname := r.Name() vers := proj.projState.GetInstalledVersion(rname) if vers != nil { ok := rdesc.SatisfiesVersion(vers, r.VersionRequirements()) if !ok && !upgrade { util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: Installed "+ "version %s of repository %s does not match desired "+ "version %s in project file. You can fix this by either upgrading"+ " your repository, or modifying the project.yml file.\n", vers, rname, r.VersionRequirementsString()) return true, err } else { if !upgrade { util.StatusMessage(util.VERBOSITY_VERBOSE, "%s correct version already installed\n", r.Name()) return true, nil } else { skip, err := proj.upgradeCheck(r, vers, force) return skip, err } } } else { // Fallthrough and perform the installation. // Check to make sure that this repository contains a version // that can satisfy. _, _, ok := rdesc.Match(r) if !ok { fmt.Printf("WARNING: No matching repository version found for repository "+ "%s specified in project.\n", r.Name()) return true, err } } return false, nil }
func ReadLocalPackages(repo *repo.Repo, basePath string) ( pkgMap *map[string]interfaces.PackageInterface, warnings []string, err error) { pkgMap = &map[string]interfaces.PackageInterface{} warnings = []string{} searchPaths, err := repo.FilteredSearchList("") if err != nil { return } for _, path := range searchPaths { pkgDir := basePath + "/" + path if util.NodeNotExist(pkgDir) { continue } var dirList []string if dirList, err = repo.FilteredSearchList(path); err != nil { return } for _, subDir := range dirList { var subWarnings []string subWarnings, err = ReadLocalPackageRecursive(repo, *pkgMap, basePath, filepath.Join(path, subDir)) warnings = append(warnings, subWarnings...) if err != nil { return } } } return }
func (proj *Project) upgradeCheck(r *repo.Repo, vers *repo.Version, force bool) (bool, error) { rdesc, err := r.GetRepoDesc() if err != nil { return false, err } branch, newVers, _ := rdesc.Match(r) if newVers == nil { util.StatusMessage(util.VERBOSITY_DEFAULT, "No matching version to upgrade to "+ "found for %s. Please check your project requirements.", r.Name()) return false, util.NewNewtError(fmt.Sprintf("Cannot find a "+ "version of repository %s that matches project requirements.", r.Name())) } // If the change between the old repository and the new repository would cause // and upgrade. Then prompt for an upgrade response, unless the force option // is present. if vers.CompareVersions(newVers, vers) != 0 || vers.Stability() != newVers.Stability() { if !force { str := "" if newVers.Stability() != repo.VERSION_STABILITY_NONE { str += "(" + branch + ")" } fmt.Printf("Would you like to upgrade repository %s from %s to %s %s? [Yn] ", r.Name(), vers.String(), newVers.String(), str) line, more, err := bufio.NewReader(os.Stdin).ReadLine() if more || err != nil { return false, util.NewNewtError(fmt.Sprintf( "Couldn't read upgrade response: %s\n", err.Error())) } // Anything but no means yes. answer := strings.ToUpper(strings.Trim(string(line), " ")) if answer == "N" || answer == "NO" { fmt.Printf("User says don't upgrade, skipping upgrade of %s\n", r.Name()) return true, nil } } } else { util.StatusMessage(util.VERBOSITY_VERBOSE, "Repository %s doesn't need to be upgraded, latest "+ "version installed.\n", r.Name()) return true, nil } return false, nil }