mirror of
https://github.com/Jguer/yay.git
synced 2025-10-03 00:04:05 -04:00
Add utils.go
This commit is contained in:
parent
415659d1cd
commit
0c0cd4f883
42
conflicts.go
42
conflicts.go
@ -12,14 +12,6 @@ import (
|
|||||||
// Checks a single conflict against every other to be installed package's
|
// Checks a single conflict against every other to be installed package's
|
||||||
// name and its provides.
|
// name and its provides.
|
||||||
func checkInnerConflict(name string, conflict string, conflicts map[string]stringSet, dc *depCatagories) {
|
func checkInnerConflict(name string, conflict string, conflicts map[string]stringSet, dc *depCatagories) {
|
||||||
add := func(h map[string]stringSet, n string, v string) {
|
|
||||||
_, ok := h[n]
|
|
||||||
if !ok {
|
|
||||||
h[n] = make(stringSet)
|
|
||||||
}
|
|
||||||
h[n].set(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
deps, err := gopkg.ParseDeps([]string{conflict})
|
deps, err := gopkg.ParseDeps([]string{conflict})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -36,7 +28,7 @@ func checkInnerConflict(name string, conflict string, conflicts map[string]strin
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if dep.Name == pkg.Name && version.Satisfies(dep) {
|
if dep.Name == pkg.Name && version.Satisfies(dep) {
|
||||||
add(conflicts, name, pkg.Name)
|
addMapStringSet(conflicts, name, pkg.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +57,7 @@ func checkInnerConflict(name string, conflict string, conflicts map[string]strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if version != nil && version.Satisfies(dep) {
|
if version != nil && version.Satisfies(dep) {
|
||||||
add(conflicts, name, pkg.Name)
|
addMapStringSet(conflicts, name, pkg.Name)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +75,7 @@ func checkInnerConflict(name string, conflict string, conflicts map[string]strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if dep.Name == pkg.Name() && version.Satisfies(dep) {
|
if dep.Name == pkg.Name() && version.Satisfies(dep) {
|
||||||
add(conflicts, name, pkg.Name())
|
addMapStringSet(conflicts, name, pkg.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +92,7 @@ func checkInnerConflict(name string, conflict string, conflicts map[string]strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if provide.Mod == alpm.DepModAny {
|
if provide.Mod == alpm.DepModAny {
|
||||||
add(conflicts, name, pkg.Name())
|
addMapStringSet(conflicts, name, pkg.Name())
|
||||||
return fmt.Errorf("")
|
return fmt.Errorf("")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +102,7 @@ func checkInnerConflict(name string, conflict string, conflicts map[string]strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if version.Satisfies(dep) {
|
if version.Satisfies(dep) {
|
||||||
add(conflicts, name, pkg.Name())
|
addMapStringSet(conflicts, name, pkg.Name())
|
||||||
return fmt.Errorf("")
|
return fmt.Errorf("")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,14 +135,6 @@ func checkForInnerConflicts(dc *depCatagories) (map[string]stringSet) {
|
|||||||
// Checks a provide or packagename from a to be installed package
|
// Checks a provide or packagename from a to be installed package
|
||||||
// against every already installed package's conflicts
|
// against every already installed package's conflicts
|
||||||
func checkReverseConflict(name string, provide string, conflicts map[string]stringSet) error {
|
func checkReverseConflict(name string, provide string, conflicts map[string]stringSet) error {
|
||||||
add := func(h map[string]stringSet, n string, v string) {
|
|
||||||
_, ok := h[n]
|
|
||||||
if !ok {
|
|
||||||
h[n] = make(stringSet)
|
|
||||||
}
|
|
||||||
h[n].set(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
var version *gopkg.CompleteVersion
|
var version *gopkg.CompleteVersion
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@ -193,7 +177,7 @@ func checkReverseConflict(name string, provide string, conflicts map[string]stri
|
|||||||
|
|
||||||
if version == nil || version.Satisfies(dep) {
|
if version == nil || version.Satisfies(dep) {
|
||||||
// Todo
|
// Todo
|
||||||
add(conflicts, name, pkg.Name() + " (" + provide + ")")
|
addMapStringSet(conflicts, name, pkg.Name() + " (" + provide + ")")
|
||||||
return fmt.Errorf("")
|
return fmt.Errorf("")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,14 +193,6 @@ func checkReverseConflict(name string, provide string, conflicts map[string]stri
|
|||||||
// Checks the conflict of a to be installed package against the package name and
|
// Checks the conflict of a to be installed package against the package name and
|
||||||
// provides of every installed package.
|
// provides of every installed package.
|
||||||
func checkConflict(name string, conflict string, conflicts map[string]stringSet) error {
|
func checkConflict(name string, conflict string, conflicts map[string]stringSet) error {
|
||||||
add := func(h map[string]stringSet, n string, v string) {
|
|
||||||
_, ok := h[n]
|
|
||||||
if !ok {
|
|
||||||
h[n] = make(stringSet)
|
|
||||||
}
|
|
||||||
h[n].set(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
localDb, err := alpmHandle.LocalDb()
|
localDb, err := alpmHandle.LocalDb()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -240,7 +216,7 @@ func checkConflict(name string, conflict string, conflicts map[string]stringSet)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if dep.Name == pkg.Name() && version.Satisfies(dep) {
|
if dep.Name == pkg.Name() && version.Satisfies(dep) {
|
||||||
add(conflicts, name, pkg.Name())
|
addMapStringSet(conflicts, name, pkg.Name())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,7 +233,7 @@ func checkConflict(name string, conflict string, conflicts map[string]stringSet)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if provide.Mod == alpm.DepModAny {
|
if provide.Mod == alpm.DepModAny {
|
||||||
add(conflicts, name, pkg.Name() + " (" + provide.Name + ")")
|
addMapStringSet(conflicts, name, pkg.Name() + " (" + provide.Name + ")")
|
||||||
return fmt.Errorf("")
|
return fmt.Errorf("")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +243,7 @@ func checkConflict(name string, conflict string, conflicts map[string]stringSet)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if version.Satisfies(dep) {
|
if version.Satisfies(dep) {
|
||||||
add(conflicts, name, pkg.Name() + " (" + provide.Name + ")")
|
addMapStringSet(conflicts, name, pkg.Name() + " (" + provide.Name + ")")
|
||||||
return fmt.Errorf("")
|
return fmt.Errorf("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,15 +471,7 @@ func depTreeRecursive(dt *depTree, localDb *alpm.Db, syncDb alpm.DbList, isMake
|
|||||||
func checkVersions(dt *depTree) error {
|
func checkVersions(dt *depTree) error {
|
||||||
depStrings := make([]string, 0)
|
depStrings := make([]string, 0)
|
||||||
has := make(map[string][]string)
|
has := make(map[string][]string)
|
||||||
|
|
||||||
add := func(h map[string][]string, n string, v string) {
|
|
||||||
_, ok := h[n]
|
|
||||||
if !ok {
|
|
||||||
h[n] = make([]string, 0, 1)
|
|
||||||
}
|
|
||||||
h[n] = append(h[n], v)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, pkg := range dt.Aur {
|
for _, pkg := range dt.Aur {
|
||||||
for _, deps := range [3][]string{pkg.Depends, pkg.MakeDepends, pkg.CheckDepends} {
|
for _, deps := range [3][]string{pkg.Depends, pkg.MakeDepends, pkg.CheckDepends} {
|
||||||
for _, dep := range deps {
|
for _, dep := range deps {
|
||||||
@ -490,12 +482,12 @@ func checkVersions(dt *depTree) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add(has, pkg.Name, pkg.Version)
|
addMapStringSlice(has, pkg.Name, pkg.Version)
|
||||||
|
|
||||||
for _, name := range pkg.Provides {
|
for _, name := range pkg.Provides {
|
||||||
_name, _ver := splitNameFromDep(name)
|
_name, _ver := splitNameFromDep(name)
|
||||||
if _ver != "" {
|
if _ver != "" {
|
||||||
add(has, _name, _ver)
|
addMapStringSlice(has, _name, _ver)
|
||||||
} else {
|
} else {
|
||||||
delete(has, _name)
|
delete(has, _name)
|
||||||
}
|
}
|
||||||
@ -510,11 +502,11 @@ func checkVersions(dt *depTree) error {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
add(has, pkg.Name(), pkg.Version())
|
addMapStringSlice(has, pkg.Name(), pkg.Version())
|
||||||
|
|
||||||
pkg.Provides().ForEach(func(dep alpm.Depend) error {
|
pkg.Provides().ForEach(func(dep alpm.Depend) error {
|
||||||
if dep.Mod != alpm.DepModAny {
|
if dep.Mod != alpm.DepModAny {
|
||||||
add(has, dep.Name, dep.Version)
|
addMapStringSlice(has, dep.Name, dep.Version)
|
||||||
} else {
|
} else {
|
||||||
delete(has, dep.Name)
|
delete(has, dep.Name)
|
||||||
}
|
}
|
||||||
|
21
install.go
21
install.go
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -676,23 +675,3 @@ func clean(pkgs []*rpc.Pkg) {
|
|||||||
os.RemoveAll(dir)
|
os.RemoveAll(dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func completeFileName(dir, name string) (string, error) {
|
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(dir)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, file := range files {
|
|
||||||
if file.IsDir() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(file.Name(), name) {
|
|
||||||
return dir + file.Name(), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
28
parser.go
28
parser.go
@ -582,34 +582,6 @@ func (parser *arguments) parseCommandLine() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type intRange struct {
|
|
||||||
min int
|
|
||||||
max int
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeIntRange(min, max int) intRange {
|
|
||||||
return intRange{
|
|
||||||
min,
|
|
||||||
max,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r intRange) get(n int) bool {
|
|
||||||
return n >= r.min && n <= r.max
|
|
||||||
}
|
|
||||||
|
|
||||||
type intRanges []intRange
|
|
||||||
|
|
||||||
func (rs intRanges) get(n int) bool {
|
|
||||||
for _, r := range rs {
|
|
||||||
if r.get(n) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
//parses input for number menus
|
//parses input for number menus
|
||||||
//supports individual selection: 1 2 3 4
|
//supports individual selection: 1 2 3 4
|
||||||
//supports range selections: 1-4 10-20
|
//supports range selections: 1-4 10-20
|
||||||
|
14
query.go
14
query.go
@ -331,20 +331,6 @@ func statistics() (info struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func min(a, b int) int {
|
|
||||||
if a < b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
func max(a, b int) int {
|
|
||||||
if a < b {
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
// Queries the aur for information about specified packages.
|
// Queries the aur for information about specified packages.
|
||||||
// All packages should be queried in a single rpc request except when the number
|
// All packages should be queried in a single rpc request except when the number
|
||||||
// of packages exceeds the number set in config.RequestSplitN.
|
// of packages exceeds the number set in config.RequestSplitN.
|
||||||
|
50
upgrade.go
50
upgrade.go
@ -7,7 +7,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"unicode"
|
|
||||||
|
|
||||||
alpm "github.com/jguer/go-alpm"
|
alpm "github.com/jguer/go-alpm"
|
||||||
pkgb "github.com/mikkeloscar/gopkgbuild"
|
pkgb "github.com/mikkeloscar/gopkgbuild"
|
||||||
@ -39,32 +38,6 @@ func (u upSlice) Less(i, j int) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func lessRunes(iRunes, jRunes []rune) bool {
|
|
||||||
max := len(iRunes)
|
|
||||||
if max > len(jRunes) {
|
|
||||||
max = len(jRunes)
|
|
||||||
}
|
|
||||||
|
|
||||||
for idx := 0; idx < max; idx++ {
|
|
||||||
ir := iRunes[idx]
|
|
||||||
jr := jRunes[idx]
|
|
||||||
|
|
||||||
lir := unicode.ToLower(ir)
|
|
||||||
ljr := unicode.ToLower(jr)
|
|
||||||
|
|
||||||
if lir != ljr {
|
|
||||||
return lir < ljr
|
|
||||||
}
|
|
||||||
|
|
||||||
// the lowercase runes are the same, so compare the original
|
|
||||||
if ir != jr {
|
|
||||||
return ir < jr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return len(iRunes) < len(jRunes)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getVersionDiff(oldVersion, newversion string) (left, right string) {
|
func getVersionDiff(oldVersion, newversion string) (left, right string) {
|
||||||
old, errOld := pkgb.NewCompleteVersion(oldVersion)
|
old, errOld := pkgb.NewCompleteVersion(oldVersion)
|
||||||
new, errNew := pkgb.NewCompleteVersion(newversion)
|
new, errNew := pkgb.NewCompleteVersion(newversion)
|
||||||
@ -256,29 +229,6 @@ func upRepo(local []alpm.Package) (upSlice, error) {
|
|||||||
return slice, nil
|
return slice, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Contains returns whether e is present in s
|
|
||||||
func containsInt(s []int, e int) bool {
|
|
||||||
for _, a := range s {
|
|
||||||
if a == e {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveIntListFromList removes all src's elements that are present in target
|
|
||||||
func removeIntListFromList(src, target []int) []int {
|
|
||||||
max := len(target)
|
|
||||||
for i := 0; i < max; i++ {
|
|
||||||
if containsInt(src, target[i]) {
|
|
||||||
target = append(target[:i], target[i+1:]...)
|
|
||||||
max--
|
|
||||||
i--
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return target
|
|
||||||
}
|
|
||||||
|
|
||||||
// upgradePkgs handles updating the cache and installing updates.
|
// upgradePkgs handles updating the cache and installing updates.
|
||||||
func upgradePkgs(dt *depTree) (stringSet, stringSet, error) {
|
func upgradePkgs(dt *depTree) (stringSet, stringSet, error) {
|
||||||
ignore := make(stringSet)
|
ignore := make(stringSet)
|
||||||
|
110
utils.go
Normal file
110
utils.go
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
|
type intRange struct {
|
||||||
|
min int
|
||||||
|
max int
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeIntRange(min, max int) intRange {
|
||||||
|
return intRange{
|
||||||
|
min,
|
||||||
|
max,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r intRange) get(n int) bool {
|
||||||
|
return n >= r.min && n <= r.max
|
||||||
|
}
|
||||||
|
|
||||||
|
type intRanges []intRange
|
||||||
|
|
||||||
|
func (rs intRanges) get(n int) bool {
|
||||||
|
for _, r := range rs {
|
||||||
|
if r.get(n) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func min(a, b int) int {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func max(a, b int) int {
|
||||||
|
if a < b {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
func addMapStringSet(h map[string]stringSet, n string, v string) {
|
||||||
|
_, ok := h[n]
|
||||||
|
if !ok {
|
||||||
|
h[n] = make(stringSet)
|
||||||
|
}
|
||||||
|
h[n].set(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addMapStringSlice(h map[string][]string, n string, v string) {
|
||||||
|
_, ok := h[n]
|
||||||
|
if !ok {
|
||||||
|
h[n] = make([]string, 0, 1)
|
||||||
|
}
|
||||||
|
h[n] = append(h[n], v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func completeFileName(dir, name string) (string, error) {
|
||||||
|
files, err := ioutil.ReadDir(dir)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range files {
|
||||||
|
if file.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(file.Name(), name) {
|
||||||
|
return dir + file.Name(), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func lessRunes(iRunes, jRunes []rune) bool {
|
||||||
|
max := len(iRunes)
|
||||||
|
if max > len(jRunes) {
|
||||||
|
max = len(jRunes)
|
||||||
|
}
|
||||||
|
|
||||||
|
for idx := 0; idx < max; idx++ {
|
||||||
|
ir := iRunes[idx]
|
||||||
|
jr := jRunes[idx]
|
||||||
|
|
||||||
|
lir := unicode.ToLower(ir)
|
||||||
|
ljr := unicode.ToLower(jr)
|
||||||
|
|
||||||
|
if lir != ljr {
|
||||||
|
return lir < ljr
|
||||||
|
}
|
||||||
|
|
||||||
|
// the lowercase runes are the same, so compare the original
|
||||||
|
if ir != jr {
|
||||||
|
return ir < jr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(iRunes) < len(jRunes)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user