yay/sync.go

106 lines
2.8 KiB
Go
Raw Normal View History

2022-09-20 00:01:19 +02:00
package main
import (
"context"
2022-11-02 00:37:27 +01:00
"fmt"
"strings"
2022-09-20 00:01:19 +02:00
"github.com/leonelquinteros/gotext"
"github.com/Jguer/yay/v12/pkg/db"
"github.com/Jguer/yay/v12/pkg/dep"
"github.com/Jguer/yay/v12/pkg/multierror"
"github.com/Jguer/yay/v12/pkg/runtime"
"github.com/Jguer/yay/v12/pkg/settings"
"github.com/Jguer/yay/v12/pkg/settings/exe"
"github.com/Jguer/yay/v12/pkg/settings/parser"
"github.com/Jguer/yay/v12/pkg/sync"
"github.com/Jguer/yay/v12/pkg/upgrade"
2022-09-20 00:01:19 +02:00
)
func syncInstall(ctx context.Context,
run *runtime.Runtime,
2022-10-28 23:58:15 +02:00
cmdArgs *parser.Arguments,
dbExecutor db.Executor,
2022-09-20 00:01:19 +02:00
) error {
aurCache := run.AURClient
2022-11-02 00:37:27 +01:00
refreshArg := cmdArgs.ExistsArg("y", "refresh")
noDeps := cmdArgs.ExistsArg("d", "nodeps")
noCheck := strings.Contains(run.Cfg.MFlags, "--nocheck")
if noDeps {
run.CmdBuilder.AddMakepkgFlag("-d")
}
2022-11-02 00:37:27 +01:00
if refreshArg && run.Cfg.Mode.AtLeastRepo() {
if errR := earlyRefresh(ctx, run.Cfg, run.CmdBuilder, cmdArgs); errR != nil {
2022-11-02 00:37:27 +01:00
return fmt.Errorf("%s - %w", gotext.Get("error refreshing databases"), errR)
}
// we may have done -Sy, our handle now has an old
// database.
if errRefresh := dbExecutor.RefreshHandle(); errRefresh != nil {
return errRefresh
}
}
2022-10-28 23:58:15 +02:00
grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm,
noDeps, noCheck, cmdArgs.ExistsArg("needed"), run.Logger.Child("grapher"))
2022-09-20 00:01:19 +02:00
2022-11-08 01:32:21 +01:00
graph, err := grapher.GraphFromTargets(ctx, nil, cmdArgs.Targets)
2022-09-20 00:01:19 +02:00
if err != nil {
return err
}
excluded := []string{}
2022-11-01 23:48:35 +01:00
if cmdArgs.ExistsArg("u", "sysupgrade") {
var errSysUp error
2022-11-15 15:44:50 +01:00
upService := upgrade.NewUpgradeService(
grapher, aurCache, dbExecutor, run.VCSStore,
run.Cfg, settings.NoConfirm, run.Logger.Child("upgrade"))
graph, errSysUp = upService.GraphUpgrades(ctx,
graph, cmdArgs.ExistsDouble("u", "sysupgrade"),
func(*upgrade.Upgrade) bool { return true })
if errSysUp != nil {
return errSysUp
}
upService.AURWarnings.Print()
excluded, errSysUp = upService.UserExcludeUpgrades(graph)
2022-11-01 23:48:35 +01:00
if errSysUp != nil {
return errSysUp
}
}
opService := sync.NewOperationService(ctx, dbExecutor, run)
multiErr := &multierror.MultiError{}
targets := graph.TopoSortedLayerMap(func(s string, ii *dep.InstallInfo) error {
if ii.Source == dep.Missing {
multiErr.Add(fmt.Errorf("%w: %s %s", ErrPackagesNotFound, s, ii.Version))
}
return nil
})
if err := multiErr.Return(); err != nil {
return err
}
return opService.Run(ctx, run, cmdArgs, targets, excluded)
}
func earlyRefresh(ctx context.Context, cfg *settings.Configuration, cmdBuilder exe.ICmdBuilder, cmdArgs *parser.Arguments) error {
arguments := cmdArgs.Copy()
if cfg.CombinedUpgrade {
arguments.DelArg("u", "sysupgrade")
}
arguments.DelArg("s", "search")
arguments.DelArg("i", "info")
arguments.DelArg("l", "list")
arguments.ClearTargets()
return cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
arguments, cfg.Mode, settings.NoConfirm))
}