yay/install.go

923 lines
24 KiB
Go
Raw Normal View History

package main
import (
2021-08-12 18:56:23 +02:00
"context"
"errors"
"fmt"
"os"
"path/filepath"
"strconv"
2018-02-21 09:41:25 +01:00
"strings"
2018-08-02 17:49:30 +02:00
"sync"
2020-10-01 13:38:03 +02:00
alpm "github.com/Jguer/go-alpm/v2"
gosrc "github.com/Morganamilo/go-srcinfo"
mapset "github.com/deckarep/golang-set/v2"
"github.com/leonelquinteros/gotext"
2021-09-08 22:28:08 +02:00
"github.com/Jguer/yay/v11/pkg/completion"
"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/dep"
"github.com/Jguer/yay/v11/pkg/download"
2021-10-11 22:22:03 +02:00
"github.com/Jguer/yay/v11/pkg/menus"
2021-09-08 22:28:08 +02:00
"github.com/Jguer/yay/v11/pkg/pgp"
"github.com/Jguer/yay/v11/pkg/query"
"github.com/Jguer/yay/v11/pkg/settings"
2022-09-20 00:01:19 +02:00
"github.com/Jguer/yay/v11/pkg/settings/exe"
2021-09-08 22:28:08 +02:00
"github.com/Jguer/yay/v11/pkg/settings/parser"
"github.com/Jguer/yay/v11/pkg/stringset"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/Jguer/yay/v11/pkg/vcs"
)
func setPkgReason(ctx context.Context,
cmdBuilder exe.ICmdBuilder,
mode parser.TargetMode,
cmdArgs *parser.Arguments, pkgs []string, exp bool,
) error {
if len(pkgs) == 0 {
return nil
}
2020-07-08 03:22:01 +02:00
cmdArgs = cmdArgs.CopyGlobal()
2022-11-01 23:48:35 +01:00
if exp {
if err := cmdArgs.AddArg("q", "D", "asexplicit"); err != nil {
return err
}
} else {
if err := cmdArgs.AddArg("q", "D", "asdeps"); err != nil {
return err
}
}
2022-11-01 23:48:35 +01:00
for _, compositePkgName := range pkgs {
pkgSplit := strings.Split(compositePkgName, "/")
2022-11-15 15:44:50 +01:00
2022-11-01 23:48:35 +01:00
pkgName := pkgSplit[0]
if len(pkgSplit) > 1 {
pkgName = pkgSplit[1]
}
2022-11-01 23:48:35 +01:00
cmdArgs.AddTarget(pkgName)
}
if err := cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
cmdArgs, mode, settings.NoConfirm)); err != nil {
2022-11-01 23:48:35 +01:00
return &SetPkgReasonError{exp: exp}
}
return nil
}
func asdeps(ctx context.Context,
cmdBuilder exe.ICmdBuilder,
mode parser.TargetMode, cmdArgs *parser.Arguments, pkgs []string,
) error {
return setPkgReason(ctx, cmdBuilder, mode, cmdArgs, pkgs, false)
2022-11-01 23:48:35 +01:00
}
func asexp(ctx context.Context,
cmdBuilder exe.ICmdBuilder,
mode parser.TargetMode, cmdArgs *parser.Arguments, pkgs []string,
) error {
return setPkgReason(ctx, cmdBuilder, mode, cmdArgs, pkgs, true)
2022-11-01 23:48:35 +01:00
}
2021-08-11 20:13:28 +02:00
// Install handles package installs.
2021-08-23 17:37:58 +02:00
func install(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Executor, ignoreProviders bool) error {
var (
do *dep.Order
srcinfos map[string]*gosrc.Srcinfo
noDeps = cmdArgs.ExistsDouble("d", "nodeps")
noCheck = strings.Contains(config.MFlags, "--nocheck")
assumeInstalled = cmdArgs.GetArgs("assume-installed")
sysupgradeArg = cmdArgs.ExistsArg("u", "sysupgrade")
refreshArg = cmdArgs.ExistsArg("y", "refresh")
warnings = query.NewWarnings()
)
if noDeps {
config.Runtime.CmdBuilder.AddMakepkgFlag("-d")
}
2021-08-09 13:26:32 +02:00
if config.Runtime.Mode.AtLeastRepo() {
Separate Pacman upgrade and AUR Upgrade by default Currently When performing a system upgrade, Yay will first refresh the database then perform the repo and AUR upgrade. This allows Yay to add some features such as better batch interaction, showing potential dependency problems before the upgrade starts and combined menus showing AUR and repo upgrades together. There has been discussion that this approach is a bad idea. The main issue people have is that the separation of the database refresh and the upgrade could lead to a partial upgrade if Yay fails between the two stages. Personally I do not like this argument, there are valid reasons to Yay to fail between these points. For example there may be dependency or conflict issues during the AUR upgrade. Yay can detect these before any installing actually starts and exit, just like how pacman will when there are dependency problems. If Yay does fail between these points, for the previously mentioned reasons or even a crash then a simple refresh will not cause a partial upgrade by itself. It is then the user's responsibility to either resolve these issues or instead perform an upgrade using pacman directly. My opinions aside, The discussions on the Arch wiki has reached a decision, this method is not recommended. So to follow the decided best practises this behaviour has been disabled by default. This behaviour can be toggled using the --[no]combinedupgrade flag It should be noted that Yay's upgrade menu will not show repo packages unless --combinedupgrade is used.
2018-06-22 15:44:38 +02:00
if config.CombinedUpgrade {
2021-03-14 23:39:55 +01:00
if refreshArg {
2021-08-23 17:37:58 +02:00
if errR := earlyRefresh(ctx, cmdArgs); errR != nil {
2022-09-20 00:44:06 +02:00
return fmt.Errorf("%s - %w", gotext.Get("error refreshing databases"), errR)
Separate Pacman upgrade and AUR Upgrade by default Currently When performing a system upgrade, Yay will first refresh the database then perform the repo and AUR upgrade. This allows Yay to add some features such as better batch interaction, showing potential dependency problems before the upgrade starts and combined menus showing AUR and repo upgrades together. There has been discussion that this approach is a bad idea. The main issue people have is that the separation of the database refresh and the upgrade could lead to a partial upgrade if Yay fails between the two stages. Personally I do not like this argument, there are valid reasons to Yay to fail between these points. For example there may be dependency or conflict issues during the AUR upgrade. Yay can detect these before any installing actually starts and exit, just like how pacman will when there are dependency problems. If Yay does fail between these points, for the previously mentioned reasons or even a crash then a simple refresh will not cause a partial upgrade by itself. It is then the user's responsibility to either resolve these issues or instead perform an upgrade using pacman directly. My opinions aside, The discussions on the Arch wiki has reached a decision, this method is not recommended. So to follow the decided best practises this behaviour has been disabled by default. This behaviour can be toggled using the --[no]combinedupgrade flag It should be noted that Yay's upgrade menu will not show repo packages unless --combinedupgrade is used.
2018-06-22 15:44:38 +02:00
}
}
2021-03-14 23:39:55 +01:00
} else if refreshArg || sysupgradeArg || len(cmdArgs.Targets) > 0 {
2021-08-23 17:37:58 +02:00
if errP := earlyPacmanCall(ctx, cmdArgs, dbExecutor); errP != nil {
return errP
Separate Pacman upgrade and AUR Upgrade by default Currently When performing a system upgrade, Yay will first refresh the database then perform the repo and AUR upgrade. This allows Yay to add some features such as better batch interaction, showing potential dependency problems before the upgrade starts and combined menus showing AUR and repo upgrades together. There has been discussion that this approach is a bad idea. The main issue people have is that the separation of the database refresh and the upgrade could lead to a partial upgrade if Yay fails between the two stages. Personally I do not like this argument, there are valid reasons to Yay to fail between these points. For example there may be dependency or conflict issues during the AUR upgrade. Yay can detect these before any installing actually starts and exit, just like how pacman will when there are dependency problems. If Yay does fail between these points, for the previously mentioned reasons or even a crash then a simple refresh will not cause a partial upgrade by itself. It is then the user's responsibility to either resolve these issues or instead perform an upgrade using pacman directly. My opinions aside, The discussions on the Arch wiki has reached a decision, this method is not recommended. So to follow the decided best practises this behaviour has been disabled by default. This behaviour can be toggled using the --[no]combinedupgrade flag It should be noted that Yay's upgrade menu will not show repo packages unless --combinedupgrade is used.
2018-06-22 15:44:38 +02:00
}
2018-07-19 20:53:17 +02:00
}
}
Separate Pacman upgrade and AUR Upgrade by default Currently When performing a system upgrade, Yay will first refresh the database then perform the repo and AUR upgrade. This allows Yay to add some features such as better batch interaction, showing potential dependency problems before the upgrade starts and combined menus showing AUR and repo upgrades together. There has been discussion that this approach is a bad idea. The main issue people have is that the separation of the database refresh and the upgrade could lead to a partial upgrade if Yay fails between the two stages. Personally I do not like this argument, there are valid reasons to Yay to fail between these points. For example there may be dependency or conflict issues during the AUR upgrade. Yay can detect these before any installing actually starts and exit, just like how pacman will when there are dependency problems. If Yay does fail between these points, for the previously mentioned reasons or even a crash then a simple refresh will not cause a partial upgrade by itself. It is then the user's responsibility to either resolve these issues or instead perform an upgrade using pacman directly. My opinions aside, The discussions on the Arch wiki has reached a decision, this method is not recommended. So to follow the decided best practises this behaviour has been disabled by default. This behaviour can be toggled using the --[no]combinedupgrade flag It should be noted that Yay's upgrade menu will not show repo packages unless --combinedupgrade is used.
2018-06-22 15:44:38 +02:00
// we may have done -Sy, our handle now has an old
// database.
2021-08-23 17:37:58 +02:00
if errRefresh := dbExecutor.RefreshHandle(); errRefresh != nil {
return errRefresh
}
Separate Pacman upgrade and AUR Upgrade by default Currently When performing a system upgrade, Yay will first refresh the database then perform the repo and AUR upgrade. This allows Yay to add some features such as better batch interaction, showing potential dependency problems before the upgrade starts and combined menus showing AUR and repo upgrades together. There has been discussion that this approach is a bad idea. The main issue people have is that the separation of the database refresh and the upgrade could lead to a partial upgrade if Yay fails between the two stages. Personally I do not like this argument, there are valid reasons to Yay to fail between these points. For example there may be dependency or conflict issues during the AUR upgrade. Yay can detect these before any installing actually starts and exit, just like how pacman will when there are dependency problems. If Yay does fail between these points, for the previously mentioned reasons or even a crash then a simple refresh will not cause a partial upgrade by itself. It is then the user's responsibility to either resolve these issues or instead perform an upgrade using pacman directly. My opinions aside, The discussions on the Arch wiki has reached a decision, this method is not recommended. So to follow the decided best practises this behaviour has been disabled by default. This behaviour can be toggled using the --[no]combinedupgrade flag It should be noted that Yay's upgrade menu will not show repo packages unless --combinedupgrade is used.
2018-06-22 15:44:38 +02:00
remoteNames := dbExecutor.InstalledRemotePackageNames()
localNames := dbExecutor.InstalledSyncPackageNames()
Separate Pacman upgrade and AUR Upgrade by default Currently When performing a system upgrade, Yay will first refresh the database then perform the repo and AUR upgrade. This allows Yay to add some features such as better batch interaction, showing potential dependency problems before the upgrade starts and combined menus showing AUR and repo upgrades together. There has been discussion that this approach is a bad idea. The main issue people have is that the separation of the database refresh and the upgrade could lead to a partial upgrade if Yay fails between the two stages. Personally I do not like this argument, there are valid reasons to Yay to fail between these points. For example there may be dependency or conflict issues during the AUR upgrade. Yay can detect these before any installing actually starts and exit, just like how pacman will when there are dependency problems. If Yay does fail between these points, for the previously mentioned reasons or even a crash then a simple refresh will not cause a partial upgrade by itself. It is then the user's responsibility to either resolve these issues or instead perform an upgrade using pacman directly. My opinions aside, The discussions on the Arch wiki has reached a decision, this method is not recommended. So to follow the decided best practises this behaviour has been disabled by default. This behaviour can be toggled using the --[no]combinedupgrade flag It should be noted that Yay's upgrade menu will not show repo packages unless --combinedupgrade is used.
2018-06-22 15:44:38 +02:00
remoteNamesCache := mapset.NewThreadUnsafeSet(remoteNames...)
localNamesCache := stringset.FromSlice(localNames)
2018-07-19 20:53:17 +02:00
2020-07-08 03:22:01 +02:00
requestTargets := cmdArgs.Copy().Targets
Separate Pacman upgrade and AUR Upgrade by default Currently When performing a system upgrade, Yay will first refresh the database then perform the repo and AUR upgrade. This allows Yay to add some features such as better batch interaction, showing potential dependency problems before the upgrade starts and combined menus showing AUR and repo upgrades together. There has been discussion that this approach is a bad idea. The main issue people have is that the separation of the database refresh and the upgrade could lead to a partial upgrade if Yay fails between the two stages. Personally I do not like this argument, there are valid reasons to Yay to fail between these points. For example there may be dependency or conflict issues during the AUR upgrade. Yay can detect these before any installing actually starts and exit, just like how pacman will when there are dependency problems. If Yay does fail between these points, for the previously mentioned reasons or even a crash then a simple refresh will not cause a partial upgrade by itself. It is then the user's responsibility to either resolve these issues or instead perform an upgrade using pacman directly. My opinions aside, The discussions on the Arch wiki has reached a decision, this method is not recommended. So to follow the decided best practises this behaviour has been disabled by default. This behaviour can be toggled using the --[no]combinedupgrade flag It should be noted that Yay's upgrade menu will not show repo packages unless --combinedupgrade is used.
2018-06-22 15:44:38 +02:00
// create the arguments to pass for the repo install
2020-07-08 03:22:01 +02:00
arguments := cmdArgs.Copy()
2020-07-05 02:45:23 +02:00
arguments.DelArg("asdeps", "asdep")
arguments.DelArg("asexplicit", "asexp")
arguments.Op = "S"
arguments.ClearTargets()
2018-02-21 09:41:25 +01:00
if config.Runtime.Mode == parser.ModeAUR {
2020-07-05 02:45:23 +02:00
arguments.DelArg("u", "sysupgrade")
}
// if we are doing -u also request all packages needing update
2021-03-14 23:39:55 +01:00
if sysupgradeArg {
2022-10-28 23:58:15 +02:00
var errSysUp error
2022-11-15 15:44:50 +01:00
2022-10-28 23:58:15 +02:00
requestTargets, errSysUp = addUpgradeTargetsToArgs(ctx, dbExecutor, cmdArgs, requestTargets, arguments)
if errSysUp != nil {
return errSysUp
}
}
2020-07-08 03:22:01 +02:00
targets := stringset.FromSlice(cmdArgs.Targets)
2021-08-12 18:56:23 +02:00
dp, err := dep.GetPool(ctx, requestTargets,
2021-05-13 07:27:24 +02:00
warnings, dbExecutor, config.Runtime.AURClient, config.Runtime.Mode,
2021-07-27 19:35:56 +02:00
ignoreProviders, settings.NoConfirm, config.Provides, config.ReBuild, config.RequestSplitN, noDeps, noCheck, assumeInstalled)
if err != nil {
return err
}
2021-08-23 17:37:58 +02:00
if errC := dp.CheckMissing(noDeps, noCheck); errC != nil {
return errC
}
if len(dp.Aur) == 0 {
if !config.CombinedUpgrade {
2021-03-14 23:39:55 +01:00
if sysupgradeArg {
fmt.Println(gotext.Get(" there is nothing to do"))
}
2021-08-11 20:13:28 +02:00
return nil
}
2020-07-08 03:22:01 +02:00
cmdArgs.Op = "S"
cmdArgs.DelArg("y", "refresh")
2021-08-11 20:13:28 +02:00
if arguments.ExistsArg("ignore") {
cmdArgs.CreateOrAppendOption("ignore", arguments.GetArgs("ignore")...)
}
2021-08-11 20:13:28 +02:00
2021-08-12 18:56:23 +02:00
return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
}
2021-08-23 17:37:58 +02:00
conflicts, errCC := dp.CheckConflicts(config.UseAsk, settings.NoConfirm, noDeps)
if errCC != nil {
return errCC
}
do = dep.GetOrder(dp, noDeps, noCheck)
for _, pkg := range do.Repo {
2020-07-05 02:45:23 +02:00
arguments.AddTarget(pkg.DB().Name() + "/" + pkg.Name())
}
for _, pkg := range dp.Groups {
2020-07-05 02:45:23 +02:00
arguments.AddTarget(pkg)
2018-03-16 02:14:34 +01:00
}
New install algorithm I have replaced the old install and dependancy algorithms with a new design that attemps to be more pacaur like. Mostly in minimizing user input. Ask every thing first then do everything with no need for more user input. It is not yet fully complete but is finished enough so that it works, should not fail in most cases and provides a base for more contributors to help address the existing problems. The new install chain is as follows: Source info about the provided targets Fetch a list of all dependancies needed to install targets I put alot of effort into fetching the dependancy tree while making the least amount of aur requests as possible. I'm actually very happy with how it turned out and yay wil now resolve dependancies noticably faster than pacaur when there are many aur dependancies. Install repo targets by passing to pacman Print dependancy tree and ask to confirm Ask to clean build if directory already exists Download all pkgbuilds Ask to edit all pkgbuilds Ask to continue with the install Download the sources for each packagebuild Build and install every package using -s to get repo deps and -i to install Ask to remove make dependancies There are still a lot of things that need to be done for a fully working system. Here are the problems I found with this system, either new or existing: Formating I am not so good at formatting myself, I thought best to leave it until last so I could get feedback on how it should look and help implementing it. Dependancy tree The dependancy tree is usually correct although I have noticed times where it doesnt detect all the dependancies that it should. I have only noticed this when there are circular dependancies so i think this might be the cause. It's not a big deal currently because makepkg -i installed repo deps for us which handles the repo deps for us and will get the correct ones. So yay might not list all the dependancies. but they will get installed so I consider this a visual bug. I have yet to see any circular dependancies in the AUR so I can not say what will happend but I#m guessing that it will break. Versioned packages/dependencies Targets and dependancies with version constriants such as 'linux>=4.1' will not be checked on the aur side of things but will be checked on the repo side. Ignorepkg/Ignoregroup Currently I do not handle this in any way but it shouldn't be too hard to implement. Conflict checking This is not currently implemented either Split Paclages Split packages are not Handles properly. If we only specify one package so install from a split package makepkg -i ends up installing them all anyway. If we specify more than one (n) package it will actually build the package base n times and reinstall every split package n times. Makepkg To get things working I decided to keep using the makepkg -i method. I plan to eventually replace this with a pacman -U based method. This should allow passing args such as --dbpath and --config to aur packages aswell as help solve some problems such as the split packages. Clean build I plan to improve the clean build choice to be a little more smart and instead of check if the directory exists, check if the package is already build and if so skip the build all together.
2018-01-17 22:48:23 +01:00
2021-08-09 13:26:32 +02:00
if len(do.Aur) == 0 && len(arguments.Targets) == 0 &&
(!cmdArgs.ExistsArg("u", "sysupgrade") || config.Runtime.Mode == parser.ModeAUR) {
fmt.Println(gotext.Get(" there is nothing to do"))
return nil
}
2018-02-16 18:18:59 +01:00
do.Print()
fmt.Println()
pkgbuildDirs := make(map[string]string, len(do.Aur))
2022-11-15 15:44:50 +01:00
for _, base := range do.Aur {
dir := filepath.Join(config.BuildDir, base.Pkgbase())
pkgbuildDirs[base.Pkgbase()] = dir
}
2022-11-15 15:44:50 +01:00
if config.CleanAfter {
defer func() {
2022-11-14 01:14:13 +01:00
cleanAfter(ctx, config.Runtime.CmdBuilder, pkgbuildDirs)
}()
2019-06-11 15:54:24 +02:00
}
if do.HasMake() {
switch config.RemoveMake {
case "yes":
defer func() {
2022-09-20 00:01:19 +02:00
err = removeMake(ctx, config.Runtime.CmdBuilder, do.GetMake())
}()
case "no":
2019-06-11 15:54:24 +02:00
break
default:
if text.ContinueTask(os.Stdin, gotext.Get("Remove make dependencies after install?"), false, settings.NoConfirm) {
defer func() {
2022-09-20 00:01:19 +02:00
err = removeMake(ctx, config.Runtime.CmdBuilder, do.GetMake())
}()
2019-06-11 15:54:24 +02:00
}
}
}
if errCleanMenu := menus.Clean(os.Stdout, config.CleanMenu,
pkgbuildDirs,
2021-10-11 22:22:03 +02:00
remoteNamesCache, settings.NoConfirm, config.AnswerClean); errCleanMenu != nil {
if errors.As(errCleanMenu, &settings.ErrUserAbort{}) {
return errCleanMenu
}
text.Errorln(errCleanMenu)
}
toSkip := pkgbuildsToSkip(do.Aur, targets)
toClone := make([]string, 0, len(do.Aur))
2021-08-11 20:13:28 +02:00
for _, base := range do.Aur {
if !toSkip.Get(base.Pkgbase()) {
toClone = append(toClone, base.Pkgbase())
}
}
if toSkipSlice := toSkip.ToSlice(); len(toSkipSlice) != 0 {
text.OperationInfoln(
gotext.Get("PKGBUILD up to date, Skipping (%d/%d): %s",
len(toSkipSlice), len(toClone), text.Cyan(strings.Join(toSkipSlice, ", "))))
}
2021-08-12 18:56:23 +02:00
cloned, errA := download.AURPKGBUILDRepos(ctx,
config.Runtime.CmdBuilder, toClone, config.AURURL, config.BuildDir, false)
if errA != nil {
return errA
}
if errDiffMenu := menus.Diff(ctx, config.Runtime.CmdBuilder, os.Stdout, pkgbuildDirs,
config.DiffMenu, remoteNamesCache,
2021-10-11 22:22:03 +02:00
cloned, settings.NoConfirm, config.AnswerDiff); errDiffMenu != nil {
if errors.As(errDiffMenu, &settings.ErrUserAbort{}) {
return errDiffMenu
}
2021-08-11 20:13:28 +02:00
text.Errorln(errDiffMenu)
}
if errM := mergePkgbuilds(ctx, config.Runtime.CmdBuilder, pkgbuildDirs); errM != nil {
2021-08-23 17:37:58 +02:00
return errM
}
srcinfos, err = parseSrcinfoFiles(pkgbuildDirs, true)
if err != nil {
return err
}
if errEditMenu := menus.Edit(os.Stdout, config.EditMenu, pkgbuildDirs,
2021-10-11 22:22:03 +02:00
config.Editor, config.EditorFlags, remoteNamesCache, srcinfos,
settings.NoConfirm, config.AnswerEdit); errEditMenu != nil {
if errors.As(errEditMenu, &settings.ErrUserAbort{}) {
return errEditMenu
}
text.Errorln(errEditMenu)
}
2018-02-16 18:18:59 +01:00
if errI := confirmIncompatibleInstall(srcinfos, dbExecutor); errI != nil {
return errI
}
if config.PGPFetch {
if _, errCPK := pgp.CheckPgpKeys(ctx, pkgbuildDirs, srcinfos, config.Runtime.CmdBuilder, settings.NoConfirm); errCPK != nil {
2021-08-23 17:37:58 +02:00
return errCPK
New install algorithm I have replaced the old install and dependancy algorithms with a new design that attemps to be more pacaur like. Mostly in minimizing user input. Ask every thing first then do everything with no need for more user input. It is not yet fully complete but is finished enough so that it works, should not fail in most cases and provides a base for more contributors to help address the existing problems. The new install chain is as follows: Source info about the provided targets Fetch a list of all dependancies needed to install targets I put alot of effort into fetching the dependancy tree while making the least amount of aur requests as possible. I'm actually very happy with how it turned out and yay wil now resolve dependancies noticably faster than pacaur when there are many aur dependancies. Install repo targets by passing to pacman Print dependancy tree and ask to confirm Ask to clean build if directory already exists Download all pkgbuilds Ask to edit all pkgbuilds Ask to continue with the install Download the sources for each packagebuild Build and install every package using -s to get repo deps and -i to install Ask to remove make dependancies There are still a lot of things that need to be done for a fully working system. Here are the problems I found with this system, either new or existing: Formating I am not so good at formatting myself, I thought best to leave it until last so I could get feedback on how it should look and help implementing it. Dependancy tree The dependancy tree is usually correct although I have noticed times where it doesnt detect all the dependancies that it should. I have only noticed this when there are circular dependancies so i think this might be the cause. It's not a big deal currently because makepkg -i installed repo deps for us which handles the repo deps for us and will get the correct ones. So yay might not list all the dependancies. but they will get installed so I consider this a visual bug. I have yet to see any circular dependancies in the AUR so I can not say what will happend but I#m guessing that it will break. Versioned packages/dependencies Targets and dependancies with version constriants such as 'linux>=4.1' will not be checked on the aur side of things but will be checked on the repo side. Ignorepkg/Ignoregroup Currently I do not handle this in any way but it shouldn't be too hard to implement. Conflict checking This is not currently implemented either Split Paclages Split packages are not Handles properly. If we only specify one package so install from a split package makepkg -i ends up installing them all anyway. If we specify more than one (n) package it will actually build the package base n times and reinstall every split package n times. Makepkg To get things working I decided to keep using the makepkg -i method. I plan to eventually replace this with a pacman -U based method. This should allow passing args such as --dbpath and --config to aur packages aswell as help solve some problems such as the split packages. Clean build I plan to improve the clean build choice to be a little more smart and instead of check if the directory exists, check if the package is already build and if so skip the build all together.
2018-01-17 22:48:23 +01:00
}
2018-03-21 01:26:56 +01:00
}
if !config.CombinedUpgrade {
2020-07-05 02:45:23 +02:00
arguments.DelArg("u", "sysupgrade")
}
2020-07-05 02:45:23 +02:00
if len(arguments.Targets) > 0 || arguments.ExistsArg("u") {
2021-08-12 18:56:23 +02:00
if errShow := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
arguments, config.Runtime.Mode, settings.NoConfirm)); errShow != nil {
return errors.New(gotext.Get("error installing repo packages"))
2018-03-21 01:26:56 +01:00
}
deps := make([]string, 0)
exp := make([]string, 0)
2018-03-21 01:26:56 +01:00
for _, pkg := range do.Repo {
if !dp.Explicit.Get(pkg.Name()) && !localNamesCache.Get(pkg.Name()) && !remoteNamesCache.Contains(pkg.Name()) {
deps = append(deps, pkg.Name())
2021-08-11 20:13:28 +02:00
continue
}
2020-07-08 03:22:01 +02:00
if cmdArgs.ExistsArg("asdeps", "asdep") && dp.Explicit.Get(pkg.Name()) {
deps = append(deps, pkg.Name())
2020-07-08 03:22:01 +02:00
} else if cmdArgs.ExistsArg("asexp", "asexplicit") && dp.Explicit.Get(pkg.Name()) {
exp = append(exp, pkg.Name())
2018-03-22 16:22:05 +01:00
}
2018-03-21 01:26:56 +01:00
}
if errDeps := asdeps(ctx, config.Runtime.CmdBuilder, config.Runtime.Mode, cmdArgs, deps); errDeps != nil {
return errDeps
2018-03-21 01:26:56 +01:00
}
2021-08-11 20:13:28 +02:00
if errExp := asexp(ctx, config.Runtime.CmdBuilder, config.Runtime.Mode, cmdArgs, exp); errExp != nil {
return errExp
}
2018-03-21 01:26:56 +01:00
}
2020-08-08 18:43:37 +02:00
go func() {
2021-08-12 18:56:23 +02:00
_ = completion.Update(ctx, config.Runtime.HTTPClient, dbExecutor,
config.AURURL, config.Runtime.CompletionPath, config.CompletionInterval, false)
2020-08-08 18:43:37 +02:00
}()
2022-09-11 23:15:31 +02:00
if errP := downloadPKGBUILDSourceFanout(ctx,
config.Runtime.CmdBuilder,
pkgbuildDirs,
true, config.MaxConcurrentDownloads); errP != nil {
2021-08-23 17:37:58 +02:00
text.Errorln(errP)
}
if errB := buildInstallPkgbuilds(ctx, cmdArgs, dbExecutor, dp, do, srcinfos, true, conflicts, noDeps, noCheck); errB != nil {
2021-08-23 17:37:58 +02:00
return errB
}
New install algorithm I have replaced the old install and dependancy algorithms with a new design that attemps to be more pacaur like. Mostly in minimizing user input. Ask every thing first then do everything with no need for more user input. It is not yet fully complete but is finished enough so that it works, should not fail in most cases and provides a base for more contributors to help address the existing problems. The new install chain is as follows: Source info about the provided targets Fetch a list of all dependancies needed to install targets I put alot of effort into fetching the dependancy tree while making the least amount of aur requests as possible. I'm actually very happy with how it turned out and yay wil now resolve dependancies noticably faster than pacaur when there are many aur dependancies. Install repo targets by passing to pacman Print dependancy tree and ask to confirm Ask to clean build if directory already exists Download all pkgbuilds Ask to edit all pkgbuilds Ask to continue with the install Download the sources for each packagebuild Build and install every package using -s to get repo deps and -i to install Ask to remove make dependancies There are still a lot of things that need to be done for a fully working system. Here are the problems I found with this system, either new or existing: Formating I am not so good at formatting myself, I thought best to leave it until last so I could get feedback on how it should look and help implementing it. Dependancy tree The dependancy tree is usually correct although I have noticed times where it doesnt detect all the dependancies that it should. I have only noticed this when there are circular dependancies so i think this might be the cause. It's not a big deal currently because makepkg -i installed repo deps for us which handles the repo deps for us and will get the correct ones. So yay might not list all the dependancies. but they will get installed so I consider this a visual bug. I have yet to see any circular dependancies in the AUR so I can not say what will happend but I#m guessing that it will break. Versioned packages/dependencies Targets and dependancies with version constriants such as 'linux>=4.1' will not be checked on the aur side of things but will be checked on the repo side. Ignorepkg/Ignoregroup Currently I do not handle this in any way but it shouldn't be too hard to implement. Conflict checking This is not currently implemented either Split Paclages Split packages are not Handles properly. If we only specify one package so install from a split package makepkg -i ends up installing them all anyway. If we specify more than one (n) package it will actually build the package base n times and reinstall every split package n times. Makepkg To get things working I decided to keep using the makepkg -i method. I plan to eventually replace this with a pacman -U based method. This should allow passing args such as --dbpath and --config to aur packages aswell as help solve some problems such as the split packages. Clean build I plan to improve the clean build choice to be a little more smart and instead of check if the directory exists, check if the package is already build and if so skip the build all together.
2018-01-17 22:48:23 +01:00
2019-06-11 15:54:24 +02:00
return nil
}
2022-11-15 15:44:50 +01:00
func addUpgradeTargetsToArgs(ctx context.Context, dbExecutor db.Executor,
cmdArgs *parser.Arguments, requestTargets []string, arguments *parser.Arguments,
) ([]string, error) {
2022-10-28 23:58:15 +02:00
ignore, targets, errUp := sysupgradeTargets(ctx, dbExecutor, cmdArgs.ExistsDouble("u", "sysupgrade"))
if errUp != nil {
return nil, errUp
}
for _, up := range targets {
cmdArgs.AddTarget(up)
requestTargets = append(requestTargets, up)
}
if len(ignore) > 0 {
arguments.CreateOrAppendOption("ignore", ignore.ToSlice()...)
}
2022-11-15 15:44:50 +01:00
2022-10-28 23:58:15 +02:00
return requestTargets, nil
}
2022-09-20 00:01:19 +02:00
func removeMake(ctx context.Context, cmdBuilder exe.ICmdBuilder, makeDeps []string) error {
removeArguments := parser.MakeArguments()
2021-08-11 20:13:28 +02:00
2020-07-05 02:45:23 +02:00
err := removeArguments.AddArg("R", "u")
if err != nil {
return err
}
2022-09-20 00:01:19 +02:00
for _, pkg := range makeDeps {
2020-07-05 02:45:23 +02:00
removeArguments.AddTarget(pkg)
}
New install algorithm I have replaced the old install and dependancy algorithms with a new design that attemps to be more pacaur like. Mostly in minimizing user input. Ask every thing first then do everything with no need for more user input. It is not yet fully complete but is finished enough so that it works, should not fail in most cases and provides a base for more contributors to help address the existing problems. The new install chain is as follows: Source info about the provided targets Fetch a list of all dependancies needed to install targets I put alot of effort into fetching the dependancy tree while making the least amount of aur requests as possible. I'm actually very happy with how it turned out and yay wil now resolve dependancies noticably faster than pacaur when there are many aur dependancies. Install repo targets by passing to pacman Print dependancy tree and ask to confirm Ask to clean build if directory already exists Download all pkgbuilds Ask to edit all pkgbuilds Ask to continue with the install Download the sources for each packagebuild Build and install every package using -s to get repo deps and -i to install Ask to remove make dependancies There are still a lot of things that need to be done for a fully working system. Here are the problems I found with this system, either new or existing: Formating I am not so good at formatting myself, I thought best to leave it until last so I could get feedback on how it should look and help implementing it. Dependancy tree The dependancy tree is usually correct although I have noticed times where it doesnt detect all the dependancies that it should. I have only noticed this when there are circular dependancies so i think this might be the cause. It's not a big deal currently because makepkg -i installed repo deps for us which handles the repo deps for us and will get the correct ones. So yay might not list all the dependancies. but they will get installed so I consider this a visual bug. I have yet to see any circular dependancies in the AUR so I can not say what will happend but I#m guessing that it will break. Versioned packages/dependencies Targets and dependancies with version constriants such as 'linux>=4.1' will not be checked on the aur side of things but will be checked on the repo side. Ignorepkg/Ignoregroup Currently I do not handle this in any way but it shouldn't be too hard to implement. Conflict checking This is not currently implemented either Split Paclages Split packages are not Handles properly. If we only specify one package so install from a split package makepkg -i ends up installing them all anyway. If we specify more than one (n) package it will actually build the package base n times and reinstall every split package n times. Makepkg To get things working I decided to keep using the makepkg -i method. I plan to eventually replace this with a pacman -U based method. This should allow passing args such as --dbpath and --config to aur packages aswell as help solve some problems such as the split packages. Clean build I plan to improve the clean build choice to be a little more smart and instead of check if the directory exists, check if the package is already build and if so skip the build all together.
2018-01-17 22:48:23 +01:00
oldValue := settings.NoConfirm
settings.NoConfirm = true
2022-09-20 00:01:19 +02:00
err = cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
removeArguments, config.Runtime.Mode, settings.NoConfirm))
settings.NoConfirm = oldValue
return err
}
2020-08-16 23:41:38 +02:00
func inRepos(dbExecutor db.Executor, pkg string) bool {
2020-07-10 02:36:45 +02:00
target := dep.ToTarget(pkg)
2018-07-19 20:53:17 +02:00
2019-02-04 17:56:02 +01:00
if target.DB == "aur" {
2018-07-19 20:53:17 +02:00
return false
2019-02-04 17:56:02 +01:00
} else if target.DB != "" {
2018-07-19 20:53:17 +02:00
return true
}
2020-07-10 02:36:45 +02:00
previousHideMenus := settings.HideMenus
settings.HideMenus = true
2020-08-01 01:20:00 +02:00
exists := dbExecutor.SyncSatisfierExists(target.DepString())
2020-07-10 02:36:45 +02:00
settings.HideMenus = previousHideMenus
2018-07-19 20:53:17 +02:00
2020-08-01 01:20:00 +02:00
return exists || len(dbExecutor.PackagesFromGroup(target.Name)) > 0
2018-07-19 20:53:17 +02:00
}
2021-08-12 18:56:23 +02:00
func earlyPacmanCall(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
2020-07-08 03:22:01 +02:00
arguments := cmdArgs.Copy()
2020-07-05 02:45:23 +02:00
arguments.Op = "S"
2020-07-08 03:22:01 +02:00
targets := cmdArgs.Targets
cmdArgs.ClearTargets()
2020-07-05 02:45:23 +02:00
arguments.ClearTargets()
2018-07-19 20:53:17 +02:00
if config.Runtime.Mode == parser.ModeRepo {
2020-07-05 02:45:23 +02:00
arguments.Targets = targets
2018-07-19 20:53:17 +02:00
} else {
// separate aur and repo targets
2018-07-19 20:53:17 +02:00
for _, target := range targets {
2020-08-01 01:20:00 +02:00
if inRepos(dbExecutor, target) {
2020-07-05 02:45:23 +02:00
arguments.AddTarget(target)
2018-07-19 20:53:17 +02:00
} else {
2020-07-08 03:22:01 +02:00
cmdArgs.AddTarget(target)
2018-07-19 20:53:17 +02:00
}
}
}
2020-07-08 03:22:01 +02:00
if cmdArgs.ExistsArg("y", "refresh") || cmdArgs.ExistsArg("u", "sysupgrade") || len(arguments.Targets) > 0 {
2021-08-12 18:56:23 +02:00
if err := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
arguments, config.Runtime.Mode, settings.NoConfirm)); err != nil {
return errors.New(gotext.Get("error installing repo packages"))
2018-07-19 20:53:17 +02:00
}
}
return nil
}
2021-08-12 18:56:23 +02:00
func earlyRefresh(ctx context.Context, cmdArgs *parser.Arguments) error {
2020-07-08 03:22:01 +02:00
arguments := cmdArgs.Copy()
cmdArgs.DelArg("y", "refresh")
2020-07-05 02:45:23 +02:00
arguments.DelArg("u", "sysupgrade")
arguments.DelArg("s", "search")
arguments.DelArg("i", "info")
arguments.DelArg("l", "list")
arguments.ClearTargets()
2021-08-11 20:13:28 +02:00
2021-08-12 18:56:23 +02:00
return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
arguments, config.Runtime.Mode, settings.NoConfirm))
2018-07-19 20:53:17 +02:00
}
func confirmIncompatibleInstall(srcinfos map[string]*gosrc.Srcinfo, dbExecutor db.Executor) error {
incompatible := []string{}
2021-08-11 20:13:28 +02:00
alpmArch, err := dbExecutor.AlpmArchitectures()
if err != nil {
return err
}
2018-03-21 01:26:56 +01:00
nextpkg:
for base, srcinfo := range srcinfos {
for _, arch := range srcinfo.Arch {
2022-09-06 23:38:47 +02:00
if db.ArchIsSupported(alpmArch, arch) {
continue nextpkg
}
}
incompatible = append(incompatible, base)
}
if len(incompatible) > 0 {
text.Warnln(gotext.Get("The following packages are not compatible with your architecture:"))
2021-08-11 20:13:28 +02:00
for _, pkg := range incompatible {
fmt.Print(" " + text.Cyan(pkg))
}
fmt.Println()
if !text.ContinueTask(os.Stdin, gotext.Get("Try to build them anyway?"), true, settings.NoConfirm) {
return &settings.ErrUserAbort{}
}
}
return nil
}
func parsePackageList(ctx context.Context, cmdBuilder exe.ICmdBuilder,
dir string,
) (pkgdests map[string]string, pkgVersion string, err error) {
stdout, stderr, err := cmdBuilder.Capture(
cmdBuilder.BuildMakepkgCmd(ctx, dir, "--packagelist"))
if err != nil {
return nil, "", fmt.Errorf("%s %s", stderr, err)
}
lines := strings.Split(stdout, "\n")
pkgdests = make(map[string]string)
for _, line := range lines {
if line == "" {
continue
}
fileName := filepath.Base(line)
split := strings.Split(fileName, "-")
if len(split) < 4 {
return nil, "", errors.New(gotext.Get("cannot find package name: %v", split))
}
// pkgname-pkgver-pkgrel-arch.pkgext
// This assumes 3 dashes after the pkgname, Will cause an error
// if the PKGEXT contains a dash. Please no one do that.
pkgName := strings.Join(split[:len(split)-3], "-")
pkgVersion = strings.Join(split[len(split)-3:len(split)-1], "-")
pkgdests[pkgName] = line
}
if len(pkgdests) == 0 {
return nil, "", &NoPkgDestsFoundError{dir}
}
return pkgdests, pkgVersion, nil
}
func parseSrcinfoFiles(pkgBuildDirs map[string]string, errIsFatal bool) (map[string]*gosrc.Srcinfo, error) {
srcinfos := make(map[string]*gosrc.Srcinfo)
2021-08-11 20:13:28 +02:00
k := 0
for base, dir := range pkgBuildDirs {
text.OperationInfoln(gotext.Get("(%d/%d) Parsing SRCINFO: %s", k+1, len(pkgBuildDirs), text.Cyan(base)))
pkgbuild, err := gosrc.ParseFile(filepath.Join(dir, ".SRCINFO"))
if err != nil {
if !errIsFatal {
text.Warnln(gotext.Get("failed to parse %s -- skipping: %s", base, err))
continue
}
2021-08-11 20:13:28 +02:00
return nil, errors.New(gotext.Get("failed to parse %s: %s", base, err))
}
srcinfos[base] = pkgbuild
k++
}
return srcinfos, nil
}
2020-07-10 02:36:45 +02:00
func pkgbuildsToSkip(bases []dep.Base, targets stringset.StringSet) stringset.StringSet {
toSkip := make(stringset.StringSet)
for _, base := range bases {
isTarget := false
for _, pkg := range base {
isTarget = isTarget || targets.Get(pkg.Name)
}
if (config.ReDownload == "yes" && isTarget) || config.ReDownload == "all" {
continue
}
dir := filepath.Join(config.BuildDir, base.Pkgbase(), ".SRCINFO")
pkgbuild, err := gosrc.ParseFile(dir)
if err == nil {
if db.VerCmp(pkgbuild.Version(), base.Version()) >= 0 {
toSkip.Set(base.Pkgbase())
}
}
}
return toSkip
}
func gitMerge(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string) error {
_, stderr, err := cmdBuilder.Capture(
cmdBuilder.BuildGitCmd(ctx,
dir, "reset", "--hard", "HEAD"))
if err != nil {
return errors.New(gotext.Get("error resetting %s: %s", dir, stderr))
}
_, stderr, err = cmdBuilder.Capture(
cmdBuilder.BuildGitCmd(ctx,
dir, "merge", "--no-edit", "--ff"))
if err != nil {
return errors.New(gotext.Get("error merging %s: %s", dir, stderr))
}
return nil
}
func mergePkgbuilds(ctx context.Context, cmdBuilder exe.ICmdBuilder, pkgbuildDirs map[string]string) error {
for _, dir := range pkgbuildDirs {
err := gitMerge(ctx, cmdBuilder, dir)
if err != nil {
return err
2018-06-10 02:29:54 +02:00
}
}
return nil
}
func buildInstallPkgbuilds(
2021-08-12 18:56:23 +02:00
ctx context.Context,
cmdArgs *parser.Arguments,
2020-08-16 23:41:38 +02:00
dbExecutor db.Executor,
2020-07-10 02:36:45 +02:00
dp *dep.Pool,
do *dep.Order,
srcinfos map[string]*gosrc.Srcinfo,
incompatible bool,
conflicts stringset.MapStringSet, noDeps, noCheck bool,
2020-07-08 03:31:35 +02:00
) error {
deps := make([]string, 0)
exp := make([]string, 0)
2022-10-28 01:01:03 +02:00
pkgArchives := make([]string, 0)
oldConfirm := settings.NoConfirm
settings.NoConfirm = true
// remotenames: names of all non repo packages on the system
remoteNames := dbExecutor.InstalledRemotePackageNames()
localNames := dbExecutor.InstalledSyncPackageNames()
// cache as a stringset. maybe make it return a string set in the first
// place
remoteNamesCache := stringset.FromSlice(remoteNames)
localNamesCache := stringset.FromSlice(localNames)
for i, base := range do.Aur {
pkg := base.Pkgbase()
dir := filepath.Join(config.BuildDir, pkg)
built := true
satisfied := true
all:
for _, pkg := range base {
2022-08-22 23:28:53 +02:00
for _, dep := range dep.ComputeCombinedDepList(pkg, noDeps, noCheck) {
if !dp.AlpmExecutor.LocalSatisfierExists(dep) {
satisfied = false
text.Warnln(gotext.Get("%s not satisfied, flushing install queue", dep))
break all
}
}
}
if !satisfied || !config.BatchInstall {
text.Debugln("non batch installing archives:", pkgArchives)
errArchive := installPkgArchive(ctx, config.Runtime.CmdBuilder,
config.Runtime.Mode, config.Runtime.VCSStore, cmdArgs, pkgArchives)
errReason := setInstallReason(ctx, config.Runtime.CmdBuilder, config.Runtime.Mode, cmdArgs, deps, exp)
2021-08-11 20:13:28 +02:00
deps = make([]string, 0)
exp = make([]string, 0)
2022-10-28 01:01:03 +02:00
pkgArchives = make([]string, 0) // reset the pkgarchives
2021-08-11 20:13:28 +02:00
2022-10-28 01:01:03 +02:00
if errArchive != nil || errReason != nil {
if i != 0 {
go config.Runtime.VCSStore.RemovePackage([]string{do.Aur[i-1].String()})
}
2022-10-28 01:01:03 +02:00
if errArchive != nil {
return errArchive
}
return errReason
}
}
srcinfo := srcinfos[pkg]
args := []string{"--nobuild", "-fC"}
if incompatible {
args = append(args, "--ignorearch")
}
// pkgver bump
if err := config.Runtime.CmdBuilder.Show(
2021-08-12 18:56:23 +02:00
config.Runtime.CmdBuilder.BuildMakepkgCmd(ctx, dir, args...)); err != nil {
return errors.New(gotext.Get("error making: %s", base.String()))
}
pkgdests, pkgVersion, errList := parsePackageList(ctx, config.Runtime.CmdBuilder, dir)
if errList != nil {
return errList
}
isExplicit := false
for _, b := range base {
isExplicit = isExplicit || dp.Explicit.Get(b.Name)
}
2021-08-11 20:13:28 +02:00
2018-09-04 21:01:49 +02:00
if config.ReBuild == "no" || (config.ReBuild == "yes" && !isExplicit) {
for _, split := range base {
pkgdest, ok := pkgdests[split.Name]
if !ok {
return &PkgDestNotInListError{split.Name}
}
if _, errStat := os.Stat(pkgdest); os.IsNotExist(errStat) {
built = false
} else if errStat != nil {
return errStat
}
}
} else {
built = false
}
2020-07-05 02:45:23 +02:00
if cmdArgs.ExistsArg("needed") {
installed := true
for _, split := range base {
2020-07-29 01:53:25 +02:00
installed = dp.AlpmExecutor.IsCorrectVersionInstalled(split.Name, pkgVersion)
}
if installed {
err := config.Runtime.CmdBuilder.Show(
2021-08-12 18:56:23 +02:00
config.Runtime.CmdBuilder.BuildMakepkgCmd(ctx,
2020-08-22 01:24:52 +02:00
dir, "-c", "--nobuild", "--noextract", "--ignorearch"))
if err != nil {
return errors.New(gotext.Get("error making: %s", err))
}
2020-08-17 00:09:43 +02:00
fmt.Fprintln(os.Stdout, gotext.Get("%s is up to date -- skipping", text.Cyan(pkg+"-"+pkgVersion)))
2021-08-11 20:13:28 +02:00
continue
}
}
if built {
err := config.Runtime.CmdBuilder.Show(
2021-08-12 18:56:23 +02:00
config.Runtime.CmdBuilder.BuildMakepkgCmd(ctx,
2020-08-22 01:24:52 +02:00
dir, "-c", "--nobuild", "--noextract", "--ignorearch"))
if err != nil {
return errors.New(gotext.Get("error making: %s", err))
}
2020-08-17 00:09:43 +02:00
text.Warnln(gotext.Get("%s already made -- skipping build", text.Cyan(pkg+"-"+pkgVersion)))
} else {
args := []string{"-cf", "--noconfirm", "--noextract", "--noprepare", "--holdver"}
if incompatible {
args = append(args, "--ignorearch")
}
if errMake := config.Runtime.CmdBuilder.Show(
2021-08-12 18:56:23 +02:00
config.Runtime.CmdBuilder.BuildMakepkgCmd(ctx,
2020-08-22 01:24:52 +02:00
dir, args...)); errMake != nil {
2020-08-07 23:59:55 +02:00
return errors.New(gotext.Get("error making: %s", base.String()))
}
}
// conflicts have been checked so answer y for them
if config.UseAsk && cmdArgs.ExistsArg("ask") {
ask, _ := strconv.Atoi(cmdArgs.Options["ask"].First())
uask := alpm.QuestionType(ask) | alpm.QuestionTypeConflictPkg
cmdArgs.Options["ask"].Set(fmt.Sprint(uask))
} else {
for _, split := range base {
if _, ok := conflicts[split.Name]; ok {
settings.NoConfirm = false
2021-08-11 20:13:28 +02:00
break
}
}
}
var errAdd error
2021-08-11 20:13:28 +02:00
for _, split := range base {
2021-08-11 22:24:51 +02:00
for suffix, optional := range map[string]bool{"": false, "-debug": true} {
2022-10-28 01:01:03 +02:00
deps, exp, pkgArchives, errAdd = doAddTarget(dp, localNamesCache, remoteNamesCache,
cmdArgs, pkgdests, deps, exp, split.Name+suffix, optional, pkgArchives)
if errAdd != nil {
return errAdd
}
}
}
text.Debugln("deps:", deps, "exp:", exp, "pkgArchives:", pkgArchives)
var wg sync.WaitGroup
2021-08-11 20:13:28 +02:00
for _, pkg := range base {
if srcinfo == nil {
text.Errorln(gotext.Get("could not find srcinfo for: %s", pkg.Name))
break
}
2018-08-03 00:30:48 +02:00
wg.Add(1)
2021-08-11 20:13:28 +02:00
text.Debugln("checking vcs store for:", pkg.Name)
go func(name string) {
config.Runtime.VCSStore.Update(ctx, name, srcinfo.Source)
wg.Done()
}(pkg.Name)
}
2018-08-03 00:30:48 +02:00
wg.Wait()
}
text.Debugln("installing archives:", pkgArchives)
errArchive := installPkgArchive(ctx, config.Runtime.CmdBuilder, config.Runtime.Mode, config.Runtime.VCSStore, cmdArgs, pkgArchives)
2022-10-28 01:01:03 +02:00
if errArchive != nil {
go config.Runtime.VCSStore.RemovePackage([]string{do.Aur[len(do.Aur)-1].String()})
}
errReason := setInstallReason(ctx, config.Runtime.CmdBuilder, config.Runtime.Mode, cmdArgs, deps, exp)
2022-10-28 01:01:03 +02:00
if errReason != nil {
go config.Runtime.VCSStore.RemovePackage([]string{do.Aur[len(do.Aur)-1].String()})
}
settings.NoConfirm = oldConfirm
2021-08-11 20:13:28 +02:00
return nil
}
func installPkgArchive(ctx context.Context,
cmdBuilder exe.ICmdBuilder,
mode parser.TargetMode,
vcsStore vcs.Store,
cmdArgs *parser.Arguments,
pkgArchives []string,
) error {
if len(pkgArchives) == 0 {
return nil
}
2022-09-11 23:15:31 +02:00
arguments := cmdArgs.Copy()
arguments.ClearTargets()
arguments.Op = "U"
arguments.DelArg("confirm")
arguments.DelArg("noconfirm")
arguments.DelArg("c", "clean")
2022-09-12 00:18:38 +02:00
arguments.DelArg("i", "install")
2022-09-11 23:15:31 +02:00
arguments.DelArg("q", "quiet")
arguments.DelArg("y", "refresh")
arguments.DelArg("u", "sysupgrade")
arguments.DelArg("w", "downloadonly")
2022-10-28 00:38:11 +02:00
arguments.DelArg("asdeps", "asdep")
arguments.DelArg("asexplicit", "asexp")
2022-09-11 23:15:31 +02:00
2022-10-28 00:38:11 +02:00
arguments.AddTarget(pkgArchives...)
2022-09-11 23:15:31 +02:00
if errShow := cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
arguments, mode, settings.NoConfirm)); errShow != nil {
return errShow
}
if errStore := vcsStore.Save(); errStore != nil {
fmt.Fprintln(os.Stderr, errStore)
}
2022-10-28 00:38:11 +02:00
return nil
}
func setInstallReason(ctx context.Context,
cmdBuilder exe.ICmdBuilder, mode parser.TargetMode,
cmdArgs *parser.Arguments, deps, exps []string,
) error {
2022-10-28 00:38:11 +02:00
if len(deps)+len(exps) == 0 {
return nil
}
if errDeps := asdeps(ctx, cmdBuilder, mode, cmdArgs, deps); errDeps != nil {
return errDeps
}
return asexp(ctx, cmdBuilder, mode, cmdArgs, exps)
}
func doAddTarget(dp *dep.Pool, localNamesCache, remoteNamesCache stringset.StringSet,
2022-09-11 23:15:31 +02:00
cmdArgs *parser.Arguments, pkgdests map[string]string,
2022-10-28 01:01:03 +02:00
deps, exp []string, name string, optional bool, pkgArchives []string,
) (newDeps, newExp, newPkgArchives []string, err error) {
pkgdest, ok := pkgdests[name]
if !ok {
if optional {
return deps, exp, pkgArchives, nil
}
return deps, exp, pkgArchives, &PkgDestNotInListError{name}
}
if _, errStat := os.Stat(pkgdest); os.IsNotExist(errStat) {
if optional {
2022-10-28 01:01:03 +02:00
return deps, exp, pkgArchives, nil
}
return deps, exp, pkgArchives, &FindPkgDestError{pkgDest: pkgdest, name: name}
}
2022-10-28 01:01:03 +02:00
pkgArchives = append(pkgArchives, pkgdest)
2021-08-11 20:13:28 +02:00
switch {
case cmdArgs.ExistsArg("asdeps", "asdep"):
deps = append(deps, name)
2021-08-11 20:13:28 +02:00
case cmdArgs.ExistsArg("asexplicit", "asexp"):
exp = append(exp, name)
2021-08-11 20:13:28 +02:00
case !dp.Explicit.Get(name) && !localNamesCache.Get(name) && !remoteNamesCache.Get(name):
deps = append(deps, name)
2022-09-11 23:15:31 +02:00
default:
exp = append(exp, name)
}
2022-10-28 01:01:03 +02:00
return deps, exp, pkgArchives, nil
}