Skip to content

Commit

Permalink
Moved StringSet definition to types package
Browse files Browse the repository at this point in the history
  • Loading branch information
Jguer committed Oct 5, 2019
1 parent 3d31b52 commit b01790f
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 240 deletions.
16 changes: 9 additions & 7 deletions clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io/ioutil"
"os"
"path/filepath"

"github.com/Jguer/yay/v9/pkg/types"
)

// GetPkgbuild gets the pkgbuild of the package 'pkg' trying the ABS first and then the AUR trying the ABS first and then the AUR.
Expand Down Expand Up @@ -104,8 +106,8 @@ func syncClean(parser *arguments) error {
func cleanAUR(keepInstalled, keepCurrent, removeAll bool) error {
fmt.Println("removing AUR packages from cache...")

installedBases := make(stringSet)
inAURBases := make(stringSet)
installedBases := make(types.StringSet)
inAURBases := make(types.StringSet)

_, remotePackages, _, _, err := filterPackages()
if err != nil {
Expand Down Expand Up @@ -137,15 +139,15 @@ func cleanAUR(keepInstalled, keepCurrent, removeAll bool) error {
}

for _, pkg := range info {
inAURBases.set(pkg.PackageBase)
inAURBases.Set(pkg.PackageBase)
}
}

for _, pkg := range remotePackages {
if pkg.Base() != "" {
installedBases.set(pkg.Base())
installedBases.Set(pkg.Base())
} else {
installedBases.set(pkg.Name())
installedBases.Set(pkg.Name())
}
}

Expand All @@ -155,11 +157,11 @@ func cleanAUR(keepInstalled, keepCurrent, removeAll bool) error {
}

if !removeAll {
if keepInstalled && installedBases.get(file.Name()) {
if keepInstalled && installedBases.Get(file.Name()) {
continue
}

if keepCurrent && inAURBases.get(file.Name()) {
if keepCurrent && inAURBases.Get(file.Name()) {
continue
}
}
Expand Down
37 changes: 19 additions & 18 deletions depCheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"sync"

alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/types"
)

func (dp *depPool) checkInnerConflict(name string, conflict string, conflicts mapStringSet) {
func (dp *depPool) checkInnerConflict(name string, conflict string, conflicts types.MapStringSet) {
for _, pkg := range dp.Aur {
if pkg.Name == name {
continue
Expand All @@ -31,7 +32,7 @@ func (dp *depPool) checkInnerConflict(name string, conflict string, conflicts ma
}
}

func (dp *depPool) checkForwardConflict(name string, conflict string, conflicts mapStringSet) {
func (dp *depPool) checkForwardConflict(name string, conflict string, conflicts types.MapStringSet) {
dp.LocalDB.PkgCache().ForEach(func(pkg alpm.Package) error {
if pkg.Name() == name || dp.hasPackage(pkg.Name()) {
return nil
Expand All @@ -49,7 +50,7 @@ func (dp *depPool) checkForwardConflict(name string, conflict string, conflicts
})
}

func (dp *depPool) checkReverseConflict(name string, conflict string, conflicts mapStringSet) {
func (dp *depPool) checkReverseConflict(name string, conflict string, conflicts types.MapStringSet) {
for _, pkg := range dp.Aur {
if pkg.Name == name {
continue
Expand Down Expand Up @@ -79,7 +80,7 @@ func (dp *depPool) checkReverseConflict(name string, conflict string, conflicts
}
}

func (dp *depPool) checkInnerConflicts(conflicts mapStringSet) {
func (dp *depPool) checkInnerConflicts(conflicts types.MapStringSet) {
for _, pkg := range dp.Aur {
for _, conflict := range pkg.Conflicts {
dp.checkInnerConflict(pkg.Name, conflict, conflicts)
Expand All @@ -94,7 +95,7 @@ func (dp *depPool) checkInnerConflicts(conflicts mapStringSet) {
}
}

func (dp *depPool) checkForwardConflicts(conflicts mapStringSet) {
func (dp *depPool) checkForwardConflicts(conflicts types.MapStringSet) {
for _, pkg := range dp.Aur {
for _, conflict := range pkg.Conflicts {
dp.checkForwardConflict(pkg.Name, conflict, conflicts)
Expand All @@ -109,7 +110,7 @@ func (dp *depPool) checkForwardConflicts(conflicts mapStringSet) {
}
}

func (dp *depPool) checkReverseConflicts(conflicts mapStringSet) {
func (dp *depPool) checkReverseConflicts(conflicts types.MapStringSet) {
dp.LocalDB.PkgCache().ForEach(func(pkg alpm.Package) error {
if dp.hasPackage(pkg.Name()) {
return nil
Expand All @@ -124,10 +125,10 @@ func (dp *depPool) checkReverseConflicts(conflicts mapStringSet) {
})
}

func (dp *depPool) CheckConflicts() (mapStringSet, error) {
func (dp *depPool) CheckConflicts() (types.MapStringSet, error) {
var wg sync.WaitGroup
innerConflicts := make(mapStringSet)
conflicts := make(mapStringSet)
innerConflicts := make(types.MapStringSet)
conflicts := make(types.MapStringSet)
wg.Add(2)

fmt.Println(bold(cyan("::") + bold(" Checking for conflicts...")))
Expand Down Expand Up @@ -181,9 +182,9 @@ func (dp *depPool) CheckConflicts() (mapStringSet, error) {
// These are used to decide what to pass --ask to (if set) or don't pass --noconfirm to
// As we have no idea what the order is yet we add every inner conflict to the slice
for name, pkgs := range innerConflicts {
conflicts[name] = make(stringSet)
conflicts[name] = make(types.StringSet)
for pkg := range pkgs {
conflicts[pkg] = make(stringSet)
conflicts[pkg] = make(types.StringSet)
}
}

Expand All @@ -203,12 +204,12 @@ func (dp *depPool) CheckConflicts() (mapStringSet, error) {
}

type missing struct {
Good stringSet
Good types.StringSet
Missing map[string][][]string
}

func (dp *depPool) _checkMissing(dep string, stack []string, missing *missing) {
if missing.Good.get(dep) {
if missing.Good.Get(dep) {
return
}

Expand All @@ -224,11 +225,11 @@ func (dp *depPool) _checkMissing(dep string, stack []string, missing *missing) {

aurPkg := dp.findSatisfierAur(dep)
if aurPkg != nil {
missing.Good.set(dep)
missing.Good.Set(dep)
for _, deps := range [3][]string{aurPkg.Depends, aurPkg.MakeDepends, aurPkg.CheckDepends} {
for _, aurDep := range deps {
if _, err := dp.LocalDB.PkgCache().FindSatisfier(aurDep); err == nil {
missing.Good.set(aurDep)
missing.Good.Set(aurDep)
continue
}

Expand All @@ -241,10 +242,10 @@ func (dp *depPool) _checkMissing(dep string, stack []string, missing *missing) {

repoPkg := dp.findSatisfierRepo(dep)
if repoPkg != nil {
missing.Good.set(dep)
missing.Good.Set(dep)
repoPkg.Depends().ForEach(func(repoDep alpm.Depend) error {
if _, err := dp.LocalDB.PkgCache().FindSatisfier(repoDep.String()); err == nil {
missing.Good.set(repoDep.String())
missing.Good.Set(repoDep.String())
return nil
}

Expand All @@ -260,7 +261,7 @@ func (dp *depPool) _checkMissing(dep string, stack []string, missing *missing) {

func (dp *depPool) CheckMissing() error {
missing := &missing{
make(stringSet),
make(types.StringSet),
make(map[string][][]string),
}

Expand Down
13 changes: 7 additions & 6 deletions depOrder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/types"
rpc "github.com/mikkeloscar/aur"
)

Expand All @@ -22,14 +23,14 @@ func (b Base) URLPath() string {
type depOrder struct {
Aur []Base
Repo []*alpm.Package
Runtime stringSet
Runtime types.StringSet
}

func makeDepOrder() *depOrder {
return &depOrder{
make([]Base, 0),
make([]*alpm.Package, 0),
make(stringSet),
make(types.StringSet),
}
}

Expand Down Expand Up @@ -59,7 +60,7 @@ func getDepOrder(dp *depPool) *depOrder {

func (do *depOrder) orderPkgAur(pkg *rpc.Pkg, dp *depPool, runtime bool) {
if runtime {
do.Runtime.set(pkg.Name)
do.Runtime.Set(pkg.Name)
}
delete(dp.Aur, pkg.Name)

Expand Down Expand Up @@ -89,7 +90,7 @@ func (do *depOrder) orderPkgAur(pkg *rpc.Pkg, dp *depPool, runtime bool) {

func (do *depOrder) orderPkgRepo(pkg *alpm.Package, dp *depPool, runtime bool) {
if runtime {
do.Runtime.set(pkg.Name())
do.Runtime.Set(pkg.Name())
}
delete(dp.Repo, pkg.Name())

Expand Down Expand Up @@ -119,14 +120,14 @@ func (do *depOrder) getMake() []string {

for _, base := range do.Aur {
for _, pkg := range base {
if !do.Runtime.get(pkg.Name) {
if !do.Runtime.Get(pkg.Name) {
makeOnly = append(makeOnly, pkg.Name)
}
}
}

for _, pkg := range do.Repo {
if !do.Runtime.get(pkg.Name()) {
if !do.Runtime.Get(pkg.Name()) {
makeOnly = append(makeOnly, pkg.Name())
}
}
Expand Down
Loading

0 comments on commit b01790f

Please sign in to comment.