error refactor

This commit is contained in:
jguer 2022-09-20 00:44:06 +02:00
parent bc4732e9e1
commit f496dbac8b
No known key found for this signature in database
GPG Key ID: 6D6CC9BEA8556B35
8 changed files with 386 additions and 341 deletions

237
aur_install.go Normal file
View File

@ -0,0 +1,237 @@
package main
import (
"context"
"fmt"
"os"
"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/dep"
"github.com/Jguer/yay/v11/pkg/multierror"
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/settings/parser"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/leonelquinteros/gotext"
mapset "github.com/deckarep/golang-set/v2"
)
type (
PostInstallHookFunc func(ctx context.Context) error
Installer struct {
dbExecutor db.Executor
postInstallHooks []PostInstallHookFunc
}
)
func (installer *Installer) AddPostInstallHook(hook PostInstallHookFunc) {
installer.postInstallHooks = append(installer.postInstallHooks, hook)
}
func (installer *Installer) RunPostInstallHooks(ctx context.Context) error {
var errMulti multierror.MultiError
for _, hook := range installer.postInstallHooks {
if err := hook(ctx); err != nil {
errMulti.Add(err)
}
}
return errMulti.Return()
}
func (installer *Installer) Install(ctx context.Context,
cmdArgs *parser.Arguments,
targets []map[string]*dep.InstallInfo,
pkgBuildDirs map[string]string,
) error {
// Reorganize targets into layers of dependencies
for i := len(targets) - 1; i >= 0; i-- {
err := installer.handleLayer(ctx, cmdArgs, targets[i], pkgBuildDirs)
if err != nil {
// rollback
return err
}
}
return nil
}
func (installer *Installer) handleLayer(ctx context.Context,
cmdArgs *parser.Arguments, layer map[string]*dep.InstallInfo, pkgBuildDirs map[string]string,
) error {
// Install layer
nameToBaseMap := make(map[string]string, 0)
syncDeps, syncExp := mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()
aurDeps, aurExp := mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()
for name, info := range layer {
switch info.Source {
case dep.AUR, dep.SrcInfo:
nameToBaseMap[name] = *info.AURBase
switch info.Reason {
case dep.Explicit:
if cmdArgs.ExistsArg("asdeps", "asdep") {
aurDeps.Add(name)
} else {
aurExp.Add(name)
}
case dep.Dep, dep.MakeDep, dep.CheckDep:
aurDeps.Add(name)
}
case dep.Sync:
compositePkgName := fmt.Sprintf("%s/%s", *info.SyncDBName, name)
switch info.Reason {
case dep.Explicit:
if cmdArgs.ExistsArg("asdeps", "asdep") {
syncDeps.Add(compositePkgName)
} else {
syncExp.Add(compositePkgName)
}
case dep.Dep, dep.MakeDep, dep.CheckDep:
syncDeps.Add(compositePkgName)
}
}
}
text.Debugln("syncDeps", syncDeps, "SyncExp", syncExp, "aurDeps", aurDeps, "aurExp", aurExp)
errShow := installer.installSyncPackages(ctx, cmdArgs, syncDeps, syncExp)
if errShow != nil {
return ErrInstallRepoPkgs
}
errAur := installer.installAURPackages(ctx, cmdArgs, aurDeps, aurExp, nameToBaseMap, pkgBuildDirs, false)
return errAur
}
func (installer *Installer) installAURPackages(ctx context.Context,
cmdArgs *parser.Arguments,
aurDepNames, aurExpNames mapset.Set[string],
nameToBase, pkgBuildDirsByBase map[string]string,
installIncompatible bool,
) error {
deps, exp := make([]string, 0, aurDepNames.Cardinality()), make([]string, 0, aurExpNames.Cardinality())
for _, name := range aurDepNames.Union(aurExpNames).ToSlice() {
base := nameToBase[name]
dir := pkgBuildDirsByBase[base]
args := []string{"--nobuild", "-fC"}
if installIncompatible {
args = append(args, "--ignorearch")
}
// pkgver bump
if err := config.Runtime.CmdBuilder.Show(
config.Runtime.CmdBuilder.BuildMakepkgCmd(ctx, dir, args...)); err != nil {
return fmt.Errorf("%s - %w", gotext.Get("error making: %s", base), err)
}
pkgdests, _, errList := parsePackageList(ctx, dir)
if errList != nil {
return errList
}
args = []string{"-cf", "--noconfirm", "--noextract", "--noprepare", "--holdver"}
if installIncompatible {
args = append(args, "--ignorearch")
}
if errMake := config.Runtime.CmdBuilder.Show(
config.Runtime.CmdBuilder.BuildMakepkgCmd(ctx,
dir, args...)); errMake != nil {
return fmt.Errorf("%s - %w", gotext.Get("error making: %s", base), errMake)
}
names, err := installer.getNewTargets(pkgdests, name)
if err != nil {
return err
}
isDep := installer.isDep(cmdArgs, aurExpNames, name)
if isDep {
deps = append(deps, names...)
} else {
exp = append(exp, names...)
}
}
if err := doInstall(ctx, cmdArgs, deps, exp); err != nil {
return fmt.Errorf("%s - %w", fmt.Sprintf(gotext.Get("error installing:")+" %v %v", deps, exp), err)
}
return nil
}
func (*Installer) isDep(cmdArgs *parser.Arguments, aurExpNames mapset.Set[string], name string) bool {
switch {
case cmdArgs.ExistsArg("asdeps", "asdep"):
return true
case cmdArgs.ExistsArg("asexplicit", "asexp"):
return false
case aurExpNames.Contains(name):
return false
}
return true
}
func (installer *Installer) getNewTargets(pkgdests map[string]string, name string,
) ([]string, error) {
pkgdest, ok := pkgdests[name]
names := make([]string, 0, 2)
if !ok {
return nil, &PkgDestNotInListError{name: name}
}
if _, errStat := os.Stat(pkgdest); os.IsNotExist(errStat) {
return nil, &UnableToFindPkgDestError{name: name, pkgDest: pkgdest}
}
names = append(names, name)
debugName := pkgdest + "-debug"
pkgdestDebug, ok := pkgdests[debugName]
if ok {
if _, errStat := os.Stat(pkgdestDebug); errStat == nil {
names = append(names, debugName)
}
}
return names, nil
}
func (*Installer) installSyncPackages(ctx context.Context, cmdArgs *parser.Arguments,
syncDeps, // repo targets that are deps
syncExp mapset.Set[string], // repo targets that are exp
) error {
repoTargets := syncDeps.Union(syncExp).ToSlice()
if len(repoTargets) == 0 {
return nil
}
arguments := cmdArgs.Copy()
arguments.DelArg("asdeps", "asdep")
arguments.DelArg("asexplicit", "asexp")
arguments.DelArg("i", "install")
arguments.Op = "S"
arguments.ClearTargets()
arguments.AddTarget(repoTargets...)
errShow := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
arguments, config.Runtime.Mode, settings.NoConfirm))
if errD := asdeps(ctx, cmdArgs, syncDeps.ToSlice()); errD != nil {
return errD
}
if errE := asexp(ctx, cmdArgs, syncExp.ToSlice()); errE != nil {
return errE
}
return errShow
}

4
cmd.go
View File

@ -415,6 +415,10 @@ func displayNumberMenu(ctx context.Context, pkgS []string, dbExecutor db.Executo
return nil
}
if config.NewInstallEngine {
return syncInstall(ctx, config, cmdArgs, dbExecutor)
}
return install(ctx, arguments, dbExecutor, true)
}

21
errors.go Normal file
View File

@ -0,0 +1,21 @@
package main
import "github.com/leonelquinteros/gotext"
type UnableToFindPkgDestError struct {
name, pkgDest string
}
func (e *UnableToFindPkgDestError) Error() string {
return gotext.Get(
"the PKGDEST for %s is listed by makepkg but does not exist: %s",
e.name, e.pkgDest)
}
type PkgDestNotInListError struct {
name string
}
func (e *PkgDestNotInListError) Error() string {
return gotext.Get("could not find PKGDEST for: %s", e.name)
}

View File

@ -28,7 +28,7 @@ import (
"github.com/Jguer/yay/v11/pkg/text"
)
func asdeps(ctx context.Context, cmdArgs *parser.Arguments, pkgs []string) (err error) {
func asdeps(ctx context.Context, cmdArgs *parser.Arguments, pkgs []string) error {
if len(pkgs) == 0 {
return nil
}
@ -37,7 +37,7 @@ func asdeps(ctx context.Context, cmdArgs *parser.Arguments, pkgs []string) (err
_ = cmdArgs.AddArg("q", "D", "asdeps")
cmdArgs.AddTarget(pkgs...)
err = config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
err := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
if err != nil {
return errors.New(gotext.Get("error updating package install reason to dependency"))
@ -46,7 +46,7 @@ func asdeps(ctx context.Context, cmdArgs *parser.Arguments, pkgs []string) (err
return nil
}
func asexp(ctx context.Context, cmdArgs *parser.Arguments, pkgs []string) (err error) {
func asexp(ctx context.Context, cmdArgs *parser.Arguments, pkgs []string) error {
if len(pkgs) == 0 {
return nil
}
@ -55,10 +55,10 @@ func asexp(ctx context.Context, cmdArgs *parser.Arguments, pkgs []string) (err e
_ = cmdArgs.AddArg("q", "D", "asexplicit")
cmdArgs.AddTarget(pkgs...)
err = config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
err := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
if err != nil {
return errors.New(gotext.Get("error updating package install reason to explicit"))
return fmt.Errorf("%s - %w", gotext.Get("error updating package install reason to explicit"), err)
}
return nil
@ -86,7 +86,7 @@ func install(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Execu
if config.CombinedUpgrade {
if refreshArg {
if errR := earlyRefresh(ctx, cmdArgs); errR != nil {
return errors.New(gotext.Get("error refreshing databases"))
return fmt.Errorf("%s - %w", gotext.Get("error refreshing databases"), errR)
}
}
} else if refreshArg || sysupgradeArg || len(cmdArgs.Targets) > 0 {

View File

@ -4,26 +4,19 @@ package main
import (
"context"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/dep"
"github.com/Jguer/yay/v11/pkg/download"
"github.com/Jguer/yay/v11/pkg/metadata"
"github.com/Jguer/yay/v11/pkg/multierror"
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/settings/exe"
"github.com/Jguer/yay/v11/pkg/settings/parser"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/leonelquinteros/gotext"
"github.com/pkg/errors"
gosrc "github.com/Morganamilo/go-srcinfo"
mapset "github.com/deckarep/golang-set/v2"
)
var ErrInstallRepoPkgs = errors.New(gotext.Get("error installing repo packages"))
@ -64,7 +57,6 @@ func installLocalPKGBUILD(
}
topoSorted := graph.TopoSortedLayerMap()
fmt.Println(topoSorted, len(topoSorted))
preparer := &Preparer{
dbExecutor: dbExecutor,
@ -73,8 +65,7 @@ func installLocalPKGBUILD(
}
installer := &Installer{dbExecutor: dbExecutor}
err = preparer.Present(os.Stdout, topoSorted)
if err != nil {
if err = preparer.Present(os.Stdout, topoSorted); err != nil {
return err
}
@ -88,8 +79,7 @@ func installLocalPKGBUILD(
return err
}
err = installer.Install(ctx, cmdArgs, topoSorted, pkgBuildDirs)
if err != nil {
if err = installer.Install(ctx, cmdArgs, topoSorted, pkgBuildDirs); err != nil {
if errHook := installer.RunPostInstallHooks(ctx); errHook != nil {
text.Errorln(errHook)
}
@ -99,321 +89,3 @@ func installLocalPKGBUILD(
return installer.RunPostInstallHooks(ctx)
}
type Preparer struct {
dbExecutor db.Executor
cmdBuilder exe.ICmdBuilder
config *settings.Configuration
pkgBuildDirs []string
makeDeps []string
}
func (preper *Preparer) ShouldCleanMakeDeps(ctx context.Context) PostInstallHookFunc {
if len(preper.makeDeps) == 0 {
return nil
}
switch preper.config.RemoveMake {
case "yes":
break
case "no":
return nil
default:
if !text.ContinueTask(os.Stdin, gotext.Get("Remove make dependencies after install?"), false, settings.NoConfirm) {
return nil
}
}
return func(ctx context.Context) error {
return removeMake(ctx, preper.config.Runtime.CmdBuilder, preper.makeDeps)
}
}
func (preper *Preparer) Present(w io.Writer, targets []map[string]*dep.InstallInfo) error {
pkgsBySourceAndReason := map[string]map[string][]string{}
for _, layer := range targets {
for pkgName, info := range layer {
source := dep.SourceNames[info.Source]
reason := dep.ReasonNames[info.Reason]
pkgStr := text.Cyan(fmt.Sprintf("%s-%s", pkgName, info.Version))
if _, ok := pkgsBySourceAndReason[source]; !ok {
pkgsBySourceAndReason[source] = map[string][]string{}
}
pkgsBySourceAndReason[source][reason] = append(pkgsBySourceAndReason[source][reason], pkgStr)
if info.Reason == dep.MakeDep {
preper.makeDeps = append(preper.makeDeps, pkgName)
}
}
}
for source, pkgsByReason := range pkgsBySourceAndReason {
for reason, pkgs := range pkgsByReason {
fmt.Fprintf(w, text.Bold("%s %s (%d):")+" %s\n",
source,
reason,
len(pkgs),
strings.Join(pkgs, ", "))
}
}
return nil
}
func (preper *Preparer) PrepareWorkspace(ctx context.Context, targets []map[string]*dep.InstallInfo) (map[string]string, error) {
aurBases := mapset.NewThreadUnsafeSet[string]()
pkgBuildDirs := make(map[string]string, 0)
for _, layer := range targets {
for pkgName, info := range layer {
if info.Source == dep.AUR {
pkgBase := *info.AURBase
aurBases.Add(pkgBase)
pkgBuildDirs[pkgName] = filepath.Join(config.BuildDir, pkgBase)
} else if info.Source == dep.SrcInfo {
pkgBuildDirs[pkgName] = *info.SrcinfoPath
}
}
}
if _, errA := download.AURPKGBUILDRepos(ctx,
preper.cmdBuilder, aurBases.ToSlice(), config.AURURL, config.BuildDir, false); errA != nil {
return nil, errA
}
if errP := downloadPKGBUILDSourceFanout(ctx, config.Runtime.CmdBuilder,
preper.pkgBuildDirs, false, config.MaxConcurrentDownloads); errP != nil {
text.Errorln(errP)
}
return pkgBuildDirs, nil
}
type (
PostInstallHookFunc func(ctx context.Context) error
Installer struct {
dbExecutor db.Executor
postInstallHooks []PostInstallHookFunc
}
)
func (installer *Installer) AddPostInstallHook(hook PostInstallHookFunc) {
installer.postInstallHooks = append(installer.postInstallHooks, hook)
}
func (Installer *Installer) RunPostInstallHooks(ctx context.Context) error {
var errMulti multierror.MultiError
for _, hook := range Installer.postInstallHooks {
if err := hook(ctx); err != nil {
errMulti.Add(err)
}
}
return errMulti.Return()
}
func (installer *Installer) Install(ctx context.Context,
cmdArgs *parser.Arguments,
targets []map[string]*dep.InstallInfo,
pkgBuildDirs map[string]string,
) error {
// Reorganize targets into layers of dependencies
for i := len(targets) - 1; i >= 0; i-- {
err := installer.handleLayer(ctx, cmdArgs, targets[i], pkgBuildDirs)
if err != nil {
// rollback
return err
}
}
return nil
}
func (installer *Installer) handleLayer(ctx context.Context,
cmdArgs *parser.Arguments, layer map[string]*dep.InstallInfo, pkgBuildDirs map[string]string,
) error {
// Install layer
nameToBaseMap := make(map[string]string, 0)
syncDeps, syncExp := mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()
aurDeps, aurExp := mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()
for name, info := range layer {
switch info.Source {
case dep.SrcInfo:
fallthrough
case dep.AUR:
nameToBaseMap[name] = *info.AURBase
switch info.Reason {
case dep.Explicit:
if cmdArgs.ExistsArg("asdeps", "asdep") {
aurDeps.Add(name)
} else {
aurExp.Add(name)
}
case dep.CheckDep:
fallthrough
case dep.MakeDep:
fallthrough
case dep.Dep:
aurDeps.Add(name)
}
case dep.Sync:
switch info.Reason {
case dep.Explicit:
if cmdArgs.ExistsArg("asdeps", "asdep") {
syncDeps.Add(name)
} else {
syncExp.Add(name)
}
case dep.CheckDep:
fallthrough
case dep.MakeDep:
fallthrough
case dep.Dep:
syncDeps.Add(name)
}
}
}
text.Debugln("syncDeps", syncDeps, "SyncExp", syncExp, "aurDeps", aurDeps, "aurExp", aurExp)
errShow := installer.installSyncPackages(ctx, cmdArgs, syncDeps, syncExp)
if errShow != nil {
return ErrInstallRepoPkgs
}
errAur := installer.installAURPackages(ctx, cmdArgs, aurDeps, aurExp, nameToBaseMap, pkgBuildDirs, false)
return errAur
}
func (installer *Installer) installAURPackages(ctx context.Context,
cmdArgs *parser.Arguments,
aurDepNames, aurExpNames mapset.Set[string],
nameToBase, pkgBuildDirsByBase map[string]string,
installIncompatible bool,
) error {
deps, exp := make([]string, 0, aurDepNames.Cardinality()), make([]string, 0, aurExpNames.Cardinality())
for _, name := range aurDepNames.Union(aurExpNames).ToSlice() {
base := nameToBase[name]
dir := pkgBuildDirsByBase[base]
args := []string{"--nobuild", "-fC"}
if installIncompatible {
args = append(args, "--ignorearch")
}
// pkgver bump
if err := config.Runtime.CmdBuilder.Show(
config.Runtime.CmdBuilder.BuildMakepkgCmd(ctx, dir, args...)); err != nil {
return errors.New(gotext.Get("error making: %s", base))
}
pkgdests, _, errList := parsePackageList(ctx, dir)
if errList != nil {
return errList
}
args = []string{"-cf", "--noconfirm", "--noextract", "--noprepare", "--holdver"}
if installIncompatible {
args = append(args, "--ignorearch")
}
if errMake := config.Runtime.CmdBuilder.Show(
config.Runtime.CmdBuilder.BuildMakepkgCmd(ctx,
dir, args...)); errMake != nil {
return errors.New(gotext.Get("error making: %s", base))
}
names, err := installer.getNewTargets(pkgdests, name)
if err != nil {
return err
}
isDep := installer.isDep(cmdArgs, aurExpNames, name)
if isDep {
deps = append(deps, names...)
} else {
exp = append(exp, names...)
}
}
if err := doInstall(ctx, cmdArgs, deps, exp); err != nil {
return errors.New(fmt.Sprintf(gotext.Get("error installing:")+" %v %v", deps, exp))
}
return nil
}
func (*Installer) isDep(cmdArgs *parser.Arguments, aurExpNames mapset.Set[string], name string) bool {
switch {
case cmdArgs.ExistsArg("asdeps", "asdep"):
return true
case cmdArgs.ExistsArg("asexplicit", "asexp"):
return false
case aurExpNames.Contains(name):
return false
}
return true
}
func (installer *Installer) getNewTargets(pkgdests map[string]string, name string,
) ([]string, error) {
pkgdest, ok := pkgdests[name]
names := make([]string, 0, 2)
if !ok {
return nil, errors.New(gotext.Get("could not find PKGDEST for: %s", name))
}
if _, errStat := os.Stat(pkgdest); os.IsNotExist(errStat) {
return nil, errors.New(
gotext.Get(
"the PKGDEST for %s is listed by makepkg but does not exist: %s",
name, pkgdest))
}
names = append(names, name)
debugName := pkgdest + "-debug"
pkgdestDebug, ok := pkgdests[debugName]
if ok {
if _, errStat := os.Stat(pkgdestDebug); errStat == nil {
names = append(names, debugName)
}
}
return names, nil
}
func (*Installer) installSyncPackages(ctx context.Context, cmdArgs *parser.Arguments,
syncDeps, // repo targets that are deps
syncExp mapset.Set[string], // repo targets that are exp
) error {
repoTargets := syncDeps.Union(syncExp).ToSlice()
if len(repoTargets) == 0 {
return nil
}
arguments := cmdArgs.Copy()
arguments.DelArg("asdeps", "asdep")
arguments.DelArg("asexplicit", "asexp")
arguments.DelArg("i", "install")
arguments.Op = "S"
arguments.ClearTargets()
arguments.AddTarget(repoTargets...)
errShow := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
arguments, config.Runtime.Mode, settings.NoConfirm))
if errD := asdeps(ctx, cmdArgs, syncDeps.ToSlice()); errD != nil {
return errD
}
if errE := asexp(ctx, cmdArgs, syncExp.ToSlice()); errE != nil {
return errE
}
return errShow
}

View File

@ -22,6 +22,7 @@ type InstallInfo struct {
Version string
SrcinfoPath *string
AURBase *string
SyncDBName *string
}
func (i *InstallInfo) String() string {
@ -221,6 +222,7 @@ func (g *Grapher) addNodes(
text.Warnln("repo dep warn:", depName, parentPkgName, err)
}
dbName := alpmPkg.DB().Name()
g.ValidateAndSetNodeInfo(
graph,
alpmPkg.Name(),
@ -228,9 +230,10 @@ func (g *Grapher) addNodes(
Color: colorMap[depType],
Background: bgColorMap[Sync],
Value: &InstallInfo{
Source: Sync,
Reason: depType,
Version: alpmPkg.Version(),
Source: Sync,
Reason: depType,
Version: alpmPkg.Version(),
SyncDBName: &dbName,
},
})

109
preparer.go Normal file
View File

@ -0,0 +1,109 @@
package main
import (
"context"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/dep"
"github.com/Jguer/yay/v11/pkg/download"
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/settings/exe"
"github.com/Jguer/yay/v11/pkg/text"
mapset "github.com/deckarep/golang-set/v2"
"github.com/leonelquinteros/gotext"
)
type Preparer struct {
dbExecutor db.Executor
cmdBuilder exe.ICmdBuilder
config *settings.Configuration
pkgBuildDirs []string
makeDeps []string
}
func (preper *Preparer) ShouldCleanMakeDeps(ctx context.Context) PostInstallHookFunc {
if len(preper.makeDeps) == 0 {
return nil
}
switch preper.config.RemoveMake {
case "yes":
break
case "no":
return nil
default:
if !text.ContinueTask(os.Stdin, gotext.Get("Remove make dependencies after install?"), false, settings.NoConfirm) {
return nil
}
}
return func(ctx context.Context) error {
return removeMake(ctx, preper.config.Runtime.CmdBuilder, preper.makeDeps)
}
}
func (preper *Preparer) Present(w io.Writer, targets []map[string]*dep.InstallInfo) error {
pkgsBySourceAndReason := map[string]map[string][]string{}
for _, layer := range targets {
for pkgName, info := range layer {
source := dep.SourceNames[info.Source]
reason := dep.ReasonNames[info.Reason]
pkgStr := text.Cyan(fmt.Sprintf("%s-%s", pkgName, info.Version))
if _, ok := pkgsBySourceAndReason[source]; !ok {
pkgsBySourceAndReason[source] = map[string][]string{}
}
pkgsBySourceAndReason[source][reason] = append(pkgsBySourceAndReason[source][reason], pkgStr)
if info.Reason == dep.MakeDep {
preper.makeDeps = append(preper.makeDeps, pkgName)
}
}
}
for source, pkgsByReason := range pkgsBySourceAndReason {
for reason, pkgs := range pkgsByReason {
fmt.Fprintf(w, text.Bold("%s %s (%d):")+" %s\n",
source,
reason,
len(pkgs),
strings.Join(pkgs, ", "))
}
}
return nil
}
func (preper *Preparer) PrepareWorkspace(ctx context.Context, targets []map[string]*dep.InstallInfo) (map[string]string, error) {
aurBases := mapset.NewThreadUnsafeSet[string]()
pkgBuildDirs := make(map[string]string, 0)
for _, layer := range targets {
for pkgName, info := range layer {
if info.Source == dep.AUR {
pkgBase := *info.AURBase
aurBases.Add(pkgBase)
pkgBuildDirs[pkgName] = filepath.Join(config.BuildDir, pkgBase)
} else if info.Source == dep.SrcInfo {
pkgBuildDirs[pkgName] = *info.SrcinfoPath
}
}
}
if _, errA := download.AURPKGBUILDRepos(ctx,
preper.cmdBuilder, aurBases.ToSlice(), config.AURURL, config.BuildDir, false); errA != nil {
return nil, errA
}
if errP := downloadPKGBUILDSourceFanout(ctx, config.Runtime.CmdBuilder,
preper.pkgBuildDirs, false, config.MaxConcurrentDownloads); errP != nil {
text.Errorln(errP)
}
return pkgBuildDirs, nil
}

View File

@ -40,8 +40,7 @@ func syncInstall(ctx context.Context,
}
installer := &Installer{dbExecutor: dbExecutor}
err = preparer.Present(os.Stdout, topoSorted)
if err != nil {
if err = preparer.Present(os.Stdout, topoSorted); err != nil {
return err
}