Beispiel #1
0
// outdatedPackages returns {pkgname: {localver, syncver, repo}}
func outdatedPackages() map[string][3]string {
	alpmHandleLock.RLock()
	defer alpmHandleLock.RUnlock()
	h := getAlpm()
	localdb, err := h.LocalDb()
	if err != nil {
		return nil
	}
	syncs, err := h.SyncDbs()
	if err != nil {
		return nil
	}
	result := make(map[string][3]string, 16)
	locals := make(map[string]string, 100)
	syncvers := make(map[string][2]string, 100)
	localdb.PkgCache().ForEach(func(pkg alpm.Package) error {
		locals[pkg.Name()] = pkg.Version()
		return nil
	})
	for _, db := range syncs.Slice() {
		db.PkgCache().ForEach(func(pkg alpm.Package) error {
			syncver, ok := syncvers[pkg.Name()]
			if !ok || alpm.VerCmp(syncver[0], pkg.Version()) < 0 {
				syncvers[pkg.Name()] = [2]string{pkg.Version(), pkg.DB().Name()}
			}
			return nil
		})
	}
	for pkgname, localver := range locals {
		if v, ok := syncvers[pkgname]; ok && alpm.VerCmp(localver, v[0]) < 0 {
			result[pkgname] = [3]string{localver, v[0], v[1]}
		}
	}
	return result
}
Beispiel #2
0
func InstallStatus(p *alpm.Package) string {
	alpmHandleLock.RLock()
	defer alpmHandleLock.RUnlock()
	localdb, err := getAlpm().LocalDb()
	if err != nil {
		return "could not found local DB"
	}
	localp, err := localdb.PkgByName(p.Name())
	if err == nil && localp != nil {
		switch cmp := alpm.VerCmp(p.Version(), localp.Version()); {
		case cmp > 0:
			return "Upgradable"
		case cmp == 0:
			return "Installed"
		case cmp < 0:
			return "Local version is newer"
		}
	}
	return "Not installed"
}