Пример #1
0
// ListPackageDeps lists all the dependencies of the given RPM package
func (ctx *Context) ListPackageDeps(name, version, release string, depthmax int) ([]*yum.Package, error) {
	var err error
	pkg, err := ctx.yum.FindLatestProvider(name, version, release)
	if err != nil {
		return nil, fmt.Errorf("lbpkr: no such package name=%q version=%q release=%q (%v)", name, version, release, err)
	}

	deps, depsErr := ctx.yum.PackageDeps(pkg, depthmax)
	// do not handle the depsErr error just yet.
	// printout the deps we've got so far.
	if depsErr != nil {
		err = depsErr
	}

	sort.Sort(yum.Packages(deps))
	for _, pkg := range deps {
		fmt.Printf("%s\n", pkg.ID())
	}

	if depsErr != nil {
		return nil, fmt.Errorf("lbpkr: could not find dependencies for package=%q (%v)", pkg.ID(), depsErr)
	}

	return deps, err
}
Пример #2
0
// ListInstalledPackages lists all installed packages satisfying the name/vers/release patterns
func (ctx *Context) ListInstalledPackages(name, version, release string) ([]*yum.Package, error) {
	var err error
	installed, err := ctx.listInstalledPackages()
	if err != nil {
		return nil, err
	}
	filter := func(pkg [3]string) bool { return true }
	if release != "" && version != "" && name != "" {
		re_name := regexp.MustCompile(name)
		re_vers := regexp.MustCompile(version)
		re_release := regexp.MustCompile(release)
		filter = func(pkg [3]string) bool {
			return re_name.MatchString(pkg[0]) &&
				re_vers.MatchString(pkg[1]) &&
				re_release.MatchString(pkg[2])
		}
	} else if version != "" && name != "" {
		re_name := regexp.MustCompile(name)
		re_vers := regexp.MustCompile(version)
		filter = func(pkg [3]string) bool {
			return re_name.MatchString(pkg[0]) &&
				re_vers.MatchString(pkg[1])
		}

	} else if name != "" {
		re_name := regexp.MustCompile(name)
		filter = func(pkg [3]string) bool {
			return re_name.MatchString(pkg[0])
		}
	}

	pkgs := make([]*yum.Package, 0, len(installed))
	for _, pkg := range installed {
		if !filter(pkg) {
			continue
		}
		p, err := ctx.yum.FindLatestProvider(pkg[0], pkg[1], pkg[2])
		if err != nil {
			return nil, err
		}
		pkgs = append(pkgs, p)
	}
	if len(pkgs) <= 0 {
		fmt.Printf("** No Match found **\n")
		return nil, err
	}

	sort.Sort(yum.Packages(pkgs))
	for _, pkg := range pkgs {
		fmt.Printf("%s\n", pkg.ID())
	}
	return pkgs, err
}
Пример #3
0
// ListPackages lists all packages satisfying pattern (a regexp)
func (ctx *Context) ListPackages(name, version, release string) ([]*yum.Package, error) {
	var err error

	pkgs, err := ctx.yum.ListPackages(name, version, release)
	if err != nil {
		return nil, err
	}

	sort.Sort(yum.Packages(pkgs))
	for _, pkg := range pkgs {
		fmt.Printf("%s\n", pkg.ID())
	}

	ctx.msg.Infof("Total matching: %d\n", len(pkgs))
	return pkgs, err
}
Пример #4
0
// RemoveRPM removes a (set of) RPM(s) by name
func (ctx *Context) RemoveRPM(rpms [][3]string, force bool) error {
	var err error
	var required []*yum.Requires

	args := []string{"-e"}
	if force {
		args = append(args, "--nodeps")
	}

	if ctx.options.DryRun {
		args = append(args, "--test")
	}

	for _, id := range rpms {
		pkg, err := ctx.yum.FindLatestProvider(id[0], id[1], id[2])
		if err != nil {
			return err
		}

		required = append(required, pkg.Requires()...)
		args = append(args, pkg.Name())
	}

	_, err = ctx.rpm(true, args...)
	if err != nil {
		//ctx.msg.Errorf("could not remove package:\n%v", string(out))
		return err
	}

	if len(required) > 0 {
		reqs := make([]*yum.Package, 0, len(required))
		for _, req := range required {
			p, err := ctx.yum.FindLatestProvider(req.Name(), req.Version(), req.Release())
			if err != nil {
				continue
			}
			reqs = append(reqs, p)
		}
		sort.Sort(yum.Packages(reqs))
		installed, err := ctx.listInstalledPackages()
		if err != nil {
			return err
		}

		still_req := make(map[string]struct{})
		for _, pp := range installed {
			p, err := ctx.yum.FindLatestProvider(pp[0], pp[1], pp[2])
			if err != nil {
				continue
			}
			for _, r := range p.Requires() {
				pp, err := ctx.yum.FindLatestProvider(r.Name(), r.Version(), r.Release())
				if err != nil {
					continue
				}
				still_req[pp.ID()] = struct{}{}
			}
		}
		remove := make([]string, 0, len(reqs))
		// loop over installed package, if none requires one of the required package, flag it
		for _, req := range reqs {
			id := req.ID()
			if _, dup := still_req[id]; !dup {
				remove = append(remove, req.ID())
			}
		}
		if len(remove) > 0 {
			ctx.msg.Infof("packages no longer required: %v\n", strings.Join(remove, " "))
		}
	}
	return err
}