2017-04-29 19:12:12 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-05-13 07:27:24 +02:00
|
|
|
"context"
|
2020-05-04 09:24:32 +02:00
|
|
|
"errors"
|
2017-04-29 19:12:12 +02:00
|
|
|
"fmt"
|
2018-11-14 13:14:41 +01:00
|
|
|
"os"
|
2017-08-02 19:24:03 +02:00
|
|
|
"sort"
|
|
|
|
"strings"
|
2017-04-29 19:12:12 +02:00
|
|
|
|
2021-05-13 07:27:24 +02:00
|
|
|
aur "github.com/Jguer/aur"
|
2020-10-01 13:38:03 +02:00
|
|
|
alpm "github.com/Jguer/go-alpm/v2"
|
2020-05-04 09:24:32 +02:00
|
|
|
"github.com/leonelquinteros/gotext"
|
2020-05-02 16:17:20 +02:00
|
|
|
|
2021-09-08 22:28:08 +02:00
|
|
|
"github.com/Jguer/yay/v11/pkg/db"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/query"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/settings"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/settings/parser"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/stringset"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/text"
|
2017-04-29 19:12:12 +02:00
|
|
|
)
|
|
|
|
|
2021-08-11 20:13:28 +02:00
|
|
|
// Query is a collection of Results.
|
2021-05-13 07:27:24 +02:00
|
|
|
type aurQuery []aur.Pkg
|
2017-05-02 17:46:14 +02:00
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
// Query holds the results of a repository search.
|
2020-10-01 13:38:03 +02:00
|
|
|
type repoQuery []alpm.IPackage
|
2020-08-01 00:01:01 +02:00
|
|
|
|
|
|
|
func (s repoQuery) Reverse() {
|
|
|
|
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
|
|
|
|
s[i], s[j] = s[j], s[i]
|
|
|
|
}
|
|
|
|
}
|
2017-08-02 19:24:03 +02:00
|
|
|
|
|
|
|
func (q aurQuery) Len() int {
|
|
|
|
return len(q)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q aurQuery) Less(i, j int) bool {
|
2018-04-04 22:26:07 +02:00
|
|
|
var result bool
|
|
|
|
|
|
|
|
switch config.SortBy {
|
|
|
|
case "votes":
|
|
|
|
result = q[i].NumVotes > q[j].NumVotes
|
|
|
|
case "popularity":
|
|
|
|
result = q[i].Popularity > q[j].Popularity
|
|
|
|
case "name":
|
2020-07-10 02:36:45 +02:00
|
|
|
result = text.LessRunes([]rune(q[i].Name), []rune(q[j].Name))
|
2018-04-04 22:26:07 +02:00
|
|
|
case "base":
|
2020-07-10 02:36:45 +02:00
|
|
|
result = text.LessRunes([]rune(q[i].PackageBase), []rune(q[j].PackageBase))
|
2018-04-04 22:26:07 +02:00
|
|
|
case "submitted":
|
|
|
|
result = q[i].FirstSubmitted < q[j].FirstSubmitted
|
|
|
|
case "modified":
|
|
|
|
result = q[i].LastModified < q[j].LastModified
|
|
|
|
case "id":
|
|
|
|
result = q[i].ID < q[j].ID
|
|
|
|
case "baseid":
|
|
|
|
result = q[i].PackageBaseID < q[j].PackageBaseID
|
|
|
|
}
|
|
|
|
|
2020-07-05 02:01:08 +02:00
|
|
|
if config.SortMode == settings.BottomUp {
|
2018-04-04 22:26:07 +02:00
|
|
|
return !result
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
2018-04-04 22:26:07 +02:00
|
|
|
|
|
|
|
return result
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q aurQuery) Swap(i, j int) {
|
|
|
|
q[i], q[j] = q[j], q[i]
|
|
|
|
}
|
|
|
|
|
2021-05-13 07:27:24 +02:00
|
|
|
func getSearchBy(value string) aur.By {
|
2019-10-10 18:40:38 +02:00
|
|
|
switch value {
|
|
|
|
case "name":
|
2021-05-13 07:27:24 +02:00
|
|
|
return aur.Name
|
2019-10-10 18:40:38 +02:00
|
|
|
case "maintainer":
|
2021-05-13 07:27:24 +02:00
|
|
|
return aur.Maintainer
|
2019-10-10 18:40:38 +02:00
|
|
|
case "depends":
|
2021-05-13 07:27:24 +02:00
|
|
|
return aur.Depends
|
2019-10-10 18:40:38 +02:00
|
|
|
case "makedepends":
|
2021-05-13 07:27:24 +02:00
|
|
|
return aur.MakeDepends
|
2019-10-10 18:40:38 +02:00
|
|
|
case "optdepends":
|
2021-05-13 07:27:24 +02:00
|
|
|
return aur.OptDepends
|
2019-10-10 18:40:38 +02:00
|
|
|
case "checkdepends":
|
2021-05-13 07:27:24 +02:00
|
|
|
return aur.CheckDepends
|
2019-10-10 18:40:38 +02:00
|
|
|
default:
|
2021-05-13 07:27:24 +02:00
|
|
|
return aur.NameDesc
|
2019-10-10 18:40:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-11 20:13:28 +02:00
|
|
|
// NarrowSearch searches AUR and narrows based on subarguments.
|
2021-08-12 18:56:23 +02:00
|
|
|
func narrowSearch(ctx context.Context, aurClient *aur.Client, pkgS []string, sortS bool) (aurQuery, error) {
|
2021-08-11 20:13:28 +02:00
|
|
|
var (
|
|
|
|
r []aur.Pkg
|
|
|
|
err error
|
|
|
|
usedIndex int
|
|
|
|
)
|
2018-04-02 16:27:07 +02:00
|
|
|
|
2019-10-10 18:40:38 +02:00
|
|
|
by := getSearchBy(config.SearchBy)
|
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
if len(pkgS) == 0 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2018-04-02 16:27:07 +02:00
|
|
|
for i, word := range pkgS {
|
2021-08-12 18:56:23 +02:00
|
|
|
r, err = aurClient.Search(ctx, word, by)
|
2018-04-02 16:27:07 +02:00
|
|
|
if err == nil {
|
|
|
|
usedIndex = i
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2018-04-02 16:27:07 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(pkgS) == 1 {
|
|
|
|
if sortS {
|
2017-08-04 11:26:53 +02:00
|
|
|
sort.Sort(aurQuery(r))
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
return r, err
|
|
|
|
}
|
|
|
|
|
2021-08-11 20:13:28 +02:00
|
|
|
var (
|
|
|
|
aq aurQuery
|
|
|
|
n int
|
|
|
|
)
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2020-05-02 16:17:20 +02:00
|
|
|
for i := range r {
|
2017-08-02 19:24:03 +02:00
|
|
|
match := true
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-06-15 05:58:22 +02:00
|
|
|
for j, pkgN := range pkgS {
|
|
|
|
if usedIndex == j {
|
2018-04-02 16:27:07 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-10-04 22:51:18 +02:00
|
|
|
name := strings.ToLower(r[i].Name)
|
|
|
|
desc := strings.ToLower(r[i].Description)
|
|
|
|
targ := strings.ToLower(pkgN)
|
|
|
|
|
|
|
|
if !(strings.Contains(name, targ) || strings.Contains(desc, targ)) {
|
2017-08-02 19:24:03 +02:00
|
|
|
match = false
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
break
|
|
|
|
}
|
2017-05-02 17:46:14 +02:00
|
|
|
}
|
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
if match {
|
|
|
|
n++
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-05-02 16:17:20 +02:00
|
|
|
aq = append(aq, r[i])
|
2017-05-02 17:46:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
if sortS {
|
|
|
|
sort.Sort(aq)
|
|
|
|
}
|
|
|
|
|
|
|
|
return aq, err
|
2017-05-02 17:46:14 +02:00
|
|
|
}
|
|
|
|
|
2017-04-29 19:12:12 +02:00
|
|
|
// SyncSearch presents a query to the local repos and to the AUR.
|
2021-08-12 18:56:23 +02:00
|
|
|
func syncSearch(ctx context.Context, pkgS []string, aurClient *aur.Client, dbExecutor db.Executor) (err error) {
|
2020-07-10 02:36:45 +02:00
|
|
|
pkgS = query.RemoveInvalidTargets(pkgS, config.Runtime.Mode)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
|
|
|
var (
|
|
|
|
aurErr error
|
|
|
|
aq aurQuery
|
|
|
|
pq repoQuery
|
|
|
|
)
|
2018-06-04 21:36:10 +02:00
|
|
|
|
2021-08-09 13:26:32 +02:00
|
|
|
if config.Runtime.Mode.AtLeastAUR() {
|
2021-08-12 18:56:23 +02:00
|
|
|
aq, aurErr = narrowSearch(ctx, aurClient, pkgS, true)
|
2018-06-04 21:36:10 +02:00
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2021-08-09 13:26:32 +02:00
|
|
|
if config.Runtime.Mode.AtLeastRepo() {
|
2020-08-08 18:36:44 +02:00
|
|
|
pq = queryRepo(pkgS, dbExecutor)
|
2017-04-29 19:12:12 +02:00
|
|
|
}
|
|
|
|
|
2019-04-04 10:22:33 +02:00
|
|
|
switch config.SortMode {
|
2020-07-05 02:01:08 +02:00
|
|
|
case settings.TopDown:
|
2021-08-09 13:26:32 +02:00
|
|
|
if config.Runtime.Mode.AtLeastRepo() {
|
2020-08-08 18:36:44 +02:00
|
|
|
pq.printSearch(dbExecutor)
|
2018-06-04 21:36:10 +02:00
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2021-08-09 13:26:32 +02:00
|
|
|
if config.Runtime.Mode.AtLeastAUR() {
|
2020-08-08 18:36:44 +02:00
|
|
|
aq.printSearch(1, dbExecutor)
|
2018-06-04 21:36:10 +02:00
|
|
|
}
|
2020-07-05 02:01:08 +02:00
|
|
|
case settings.BottomUp:
|
2021-08-09 13:26:32 +02:00
|
|
|
if config.Runtime.Mode.AtLeastAUR() {
|
2020-08-08 18:36:44 +02:00
|
|
|
aq.printSearch(1, dbExecutor)
|
2018-06-04 21:36:10 +02:00
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2021-08-09 13:26:32 +02:00
|
|
|
if config.Runtime.Mode.AtLeastRepo() {
|
2020-08-08 18:36:44 +02:00
|
|
|
pq.printSearch(dbExecutor)
|
2019-04-04 10:22:33 +02:00
|
|
|
}
|
|
|
|
default:
|
2020-05-04 09:24:32 +02:00
|
|
|
return errors.New(gotext.Get("invalid sort mode. Fix with yay -Y --bottomup --save"))
|
2017-04-29 19:12:12 +02:00
|
|
|
}
|
|
|
|
|
2018-04-03 07:49:41 +02:00
|
|
|
if aurErr != nil {
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Errorln(gotext.Get("error during AUR search: %s", aurErr))
|
|
|
|
text.Warnln(gotext.Get("Showing repo packages only"))
|
2018-04-03 07:49:41 +02:00
|
|
|
}
|
|
|
|
|
2017-04-29 19:12:12 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SyncInfo serves as a pacman -Si for repo packages and AUR packages.
|
2021-08-12 18:56:23 +02:00
|
|
|
func syncInfo(ctx context.Context, cmdArgs *parser.Arguments, pkgS []string, dbExecutor db.Executor) error {
|
2021-08-11 20:13:28 +02:00
|
|
|
var (
|
|
|
|
info []*aur.Pkg
|
|
|
|
err error
|
|
|
|
missing = false
|
|
|
|
)
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
pkgS = query.RemoveInvalidTargets(pkgS, config.Runtime.Mode)
|
2020-08-08 18:36:44 +02:00
|
|
|
aurS, repoS := packageSlices(pkgS, dbExecutor)
|
2017-04-29 19:12:12 +02:00
|
|
|
|
2018-02-19 00:46:25 +01:00
|
|
|
if len(aurS) != 0 {
|
2019-02-04 17:56:02 +01:00
|
|
|
noDB := make([]string, 0, len(aurS))
|
2018-03-13 22:36:42 +01:00
|
|
|
|
|
|
|
for _, pkg := range aurS {
|
2020-07-10 02:36:45 +02:00
|
|
|
_, name := text.SplitDBFromName(pkg)
|
2019-02-04 17:56:02 +01:00
|
|
|
noDB = append(noDB, name)
|
2018-03-13 22:36:42 +01:00
|
|
|
}
|
|
|
|
|
2021-08-12 18:56:23 +02:00
|
|
|
info, err = query.AURInfoPrint(ctx, config.Runtime.AURClient, noDB, config.RequestSplitN)
|
2018-02-19 00:46:25 +01:00
|
|
|
if err != nil {
|
2018-06-01 05:20:49 +02:00
|
|
|
missing = true
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2018-11-14 13:14:41 +01:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2018-02-19 00:46:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 03:45:16 +01:00
|
|
|
// Repo always goes first
|
2018-01-06 14:50:54 +01:00
|
|
|
if len(repoS) != 0 {
|
2020-07-05 02:45:23 +02:00
|
|
|
arguments := cmdArgs.Copy()
|
|
|
|
arguments.ClearTargets()
|
|
|
|
arguments.AddTarget(repoS...)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2021-08-12 18:56:23 +02:00
|
|
|
err = config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
|
2021-08-08 00:57:55 +02:00
|
|
|
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
|
2018-01-06 14:50:54 +01:00
|
|
|
if err != nil {
|
2020-05-02 16:17:20 +02:00
|
|
|
return err
|
2018-01-06 14:50:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-01 05:20:49 +02:00
|
|
|
if len(aurS) != len(info) {
|
|
|
|
missing = true
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:43:02 +02:00
|
|
|
if len(info) != 0 {
|
2018-02-19 00:46:25 +01:00
|
|
|
for _, pkg := range info {
|
2020-07-08 03:22:01 +02:00
|
|
|
PrintInfo(pkg, cmdArgs.ExistsDouble("i"))
|
2017-07-05 23:30:42 +02:00
|
|
|
}
|
2017-04-29 19:12:12 +02:00
|
|
|
}
|
2018-01-20 23:37:10 +01:00
|
|
|
|
2018-06-01 05:20:49 +02:00
|
|
|
if missing {
|
|
|
|
err = fmt.Errorf("")
|
2018-05-28 14:43:02 +02:00
|
|
|
}
|
|
|
|
|
2020-05-02 16:17:20 +02:00
|
|
|
return err
|
2017-04-29 19:12:12 +02:00
|
|
|
}
|
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
// Search handles repo searches. Creates a RepoSearch struct.
|
2020-08-16 23:41:38 +02:00
|
|
|
func queryRepo(pkgInputN []string, dbExecutor db.Executor) repoQuery {
|
2020-08-01 00:01:01 +02:00
|
|
|
s := repoQuery(dbExecutor.SyncPackages(pkgInputN...))
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2020-07-05 02:01:08 +02:00
|
|
|
if config.SortMode == settings.BottomUp {
|
2020-08-01 00:01:01 +02:00
|
|
|
s.Reverse()
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-08-01 00:01:01 +02:00
|
|
|
return s
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2021-08-11 20:13:28 +02:00
|
|
|
// PackageSlices separates an input slice into aur and repo slices.
|
2021-05-13 07:27:24 +02:00
|
|
|
func packageSlices(toCheck []string, dbExecutor db.Executor) (aurNames, repoNames []string) {
|
2018-01-17 22:48:23 +01:00
|
|
|
for _, _pkg := range toCheck {
|
2020-08-01 00:01:01 +02:00
|
|
|
dbName, name := text.SplitDBFromName(_pkg)
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2021-08-08 00:08:04 +02:00
|
|
|
if dbName == "aur" || config.Runtime.Mode == parser.ModeAUR {
|
2021-05-13 07:27:24 +02:00
|
|
|
aurNames = append(aurNames, _pkg)
|
2018-03-13 22:36:42 +01:00
|
|
|
continue
|
2021-08-08 00:08:04 +02:00
|
|
|
} else if dbName != "" || config.Runtime.Mode == parser.ModeRepo {
|
2021-05-13 07:27:24 +02:00
|
|
|
repoNames = append(repoNames, _pkg)
|
2018-03-13 22:36:42 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-12-15 01:29:05 +01:00
|
|
|
if dbExecutor.SyncSatisfierExists(name) ||
|
|
|
|
len(dbExecutor.PackagesFromGroup(name)) != 0 {
|
2021-05-13 07:27:24 +02:00
|
|
|
repoNames = append(repoNames, _pkg)
|
2018-01-17 22:48:23 +01:00
|
|
|
} else {
|
2021-05-13 07:27:24 +02:00
|
|
|
aurNames = append(aurNames, _pkg)
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-13 07:27:24 +02:00
|
|
|
return aurNames, repoNames
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// HangingPackages returns a list of packages installed as deps
|
|
|
|
// and unneeded by the system
|
2021-08-11 20:13:28 +02:00
|
|
|
// removeOptional decides whether optional dependencies are counted or not.
|
2020-08-16 23:41:38 +02:00
|
|
|
func hangingPackages(removeOptional bool, dbExecutor db.Executor) (hanging []string) {
|
2018-03-24 00:45:46 +01:00
|
|
|
// safePackages represents every package in the system in one of 3 states
|
|
|
|
// State = 0 - Remove package from the system
|
|
|
|
// State = 1 - Keep package in the system; need to iterate over dependencies
|
|
|
|
// State = 2 - Keep package and have iterated over dependencies
|
|
|
|
safePackages := make(map[string]uint8)
|
|
|
|
// provides stores a mapping from the provides name back to the original package name
|
2019-10-16 23:25:40 +02:00
|
|
|
provides := make(stringset.MapStringSet)
|
2018-03-24 00:45:46 +01:00
|
|
|
|
2020-08-07 18:55:19 +02:00
|
|
|
packages := dbExecutor.LocalPackages()
|
2018-03-24 00:45:46 +01:00
|
|
|
// Mark explicit dependencies and enumerate the provides list
|
2020-08-07 18:55:19 +02:00
|
|
|
for _, pkg := range packages {
|
2018-03-24 00:45:46 +01:00
|
|
|
if pkg.Reason() == alpm.PkgReasonExplicit {
|
|
|
|
safePackages[pkg.Name()] = 1
|
|
|
|
} else {
|
|
|
|
safePackages[pkg.Name()] = 0
|
|
|
|
}
|
|
|
|
|
2020-08-07 18:55:19 +02:00
|
|
|
for _, dep := range dbExecutor.PackageProvides(pkg) {
|
2018-05-08 00:01:39 +02:00
|
|
|
provides.Add(dep.Name, pkg.Name())
|
2020-08-07 18:55:19 +02:00
|
|
|
}
|
2018-03-24 00:45:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
iterateAgain := true
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2020-08-07 18:55:19 +02:00
|
|
|
for iterateAgain {
|
|
|
|
iterateAgain = false
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-08-07 18:55:19 +02:00
|
|
|
for _, pkg := range packages {
|
|
|
|
if state := safePackages[pkg.Name()]; state == 0 || state == 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
safePackages[pkg.Name()] = 2
|
|
|
|
deps := dbExecutor.PackageDepends(pkg)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-08-07 18:55:19 +02:00
|
|
|
if !removeOptional {
|
|
|
|
deps = append(deps, dbExecutor.PackageOptionalDepends(pkg)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update state for dependencies
|
|
|
|
for _, dep := range deps {
|
|
|
|
// Don't assume a dependency is installed
|
|
|
|
state, ok := safePackages[dep.Name]
|
|
|
|
if !ok {
|
|
|
|
// Check if dep is a provides rather than actual package name
|
|
|
|
if pset, ok2 := provides[dep.Name]; ok2 {
|
|
|
|
for p := range pset {
|
|
|
|
if safePackages[p] == 0 {
|
|
|
|
iterateAgain = true
|
|
|
|
safePackages[p] = 1
|
|
|
|
}
|
2018-03-24 13:37:31 +01:00
|
|
|
}
|
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-08-07 18:55:19 +02:00
|
|
|
continue
|
2018-03-24 00:45:46 +01:00
|
|
|
}
|
|
|
|
|
2020-08-07 18:55:19 +02:00
|
|
|
if state == 0 {
|
|
|
|
iterateAgain = true
|
|
|
|
safePackages[dep.Name] = 1
|
|
|
|
}
|
2018-03-24 00:45:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build list of packages to be removed
|
2020-08-07 18:55:19 +02:00
|
|
|
for _, pkg := range packages {
|
2018-03-24 00:45:46 +01:00
|
|
|
if safePackages[pkg.Name()] == 0 {
|
|
|
|
hanging = append(hanging, pkg.Name())
|
|
|
|
}
|
2020-08-07 18:55:19 +02:00
|
|
|
}
|
2018-03-24 00:45:46 +01:00
|
|
|
|
2020-08-07 18:55:19 +02:00
|
|
|
return hanging
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2021-08-11 20:13:28 +02:00
|
|
|
// Statistics returns statistics about packages installed in system.
|
2020-08-16 23:41:38 +02:00
|
|
|
func statistics(dbExecutor db.Executor) *struct {
|
2017-08-02 19:24:03 +02:00
|
|
|
Totaln int
|
|
|
|
Expln int
|
|
|
|
TotalSize int64
|
2020-08-04 22:00:07 +02:00
|
|
|
} {
|
2021-08-11 20:13:28 +02:00
|
|
|
var (
|
|
|
|
totalSize int64
|
|
|
|
|
|
|
|
localPackages = dbExecutor.LocalPackages()
|
|
|
|
totalInstalls = 0
|
|
|
|
explicitInstalls = 0
|
|
|
|
)
|
2020-08-04 22:00:07 +02:00
|
|
|
|
|
|
|
for _, pkg := range localPackages {
|
|
|
|
totalSize += pkg.ISize()
|
|
|
|
totalInstalls++
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-08-04 22:00:07 +02:00
|
|
|
if pkg.Reason() == alpm.PkgReasonExplicit {
|
|
|
|
explicitInstalls++
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-02 16:17:20 +02:00
|
|
|
info := &struct {
|
2017-08-02 19:24:03 +02:00
|
|
|
Totaln int
|
|
|
|
Expln int
|
|
|
|
TotalSize int64
|
|
|
|
}{
|
2020-08-04 22:00:07 +02:00
|
|
|
totalInstalls, explicitInstalls, totalSize,
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2020-08-04 22:00:07 +02:00
|
|
|
return info
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|