forked from Jguer/yay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.go
186 lines (151 loc) · 4.92 KB
/
sync.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package main
import (
"context"
"errors"
"fmt"
"os"
"strings"
"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/multierror"
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/settings/parser"
"github.com/Jguer/yay/v11/pkg/srcinfo"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/Jguer/yay/v11/pkg/upgrade"
"github.com/leonelquinteros/gotext"
)
func syncInstall(ctx context.Context,
config *settings.Configuration,
cmdArgs *parser.Arguments,
dbExecutor db.Executor,
) error {
aurCache := config.Runtime.AURCache
refreshArg := cmdArgs.ExistsArg("y", "refresh")
noDeps := cmdArgs.ExistsArg("d", "nodeps")
noCheck := strings.Contains(config.MFlags, "--nocheck")
if noDeps {
config.Runtime.CmdBuilder.AddMakepkgFlag("-d")
}
if refreshArg && config.Runtime.Mode.AtLeastRepo() {
if errR := earlyRefresh(ctx, cmdArgs); errR != nil {
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
}
}
grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm,
noDeps, noCheck, cmdArgs.ExistsArg("needed"), config.Runtime.Logger.Child("grapher"))
graph, err := grapher.GraphFromTargets(ctx, nil, cmdArgs.Targets)
if err != nil {
return err
}
if cmdArgs.ExistsArg("u", "sysupgrade") {
var errSysUp error
upService := upgrade.NewUpgradeService(
grapher, aurCache, dbExecutor, config.Runtime.VCSStore,
config.Runtime, config, settings.NoConfirm, config.Runtime.Logger.Child("upgrade"))
graph, errSysUp = upService.GraphUpgrades(ctx, graph, cmdArgs.ExistsDouble("u", "sysupgrade"))
if errSysUp != nil {
return errSysUp
}
}
opService := NewOperationService(ctx, config, dbExecutor)
multiErr := &multierror.MultiError{}
targets := graph.TopoSortedLayerMap(func(s string, ii *dep.InstallInfo) error {
if ii.Source == dep.Missing {
multiErr.Add(errors.New(gotext.Get("could not find %s%s", s, ii.Version)))
}
return nil
})
if err := multiErr.Return(); err != nil {
return err
}
return opService.Run(ctx, cmdArgs, targets)
}
type OperationService struct {
ctx context.Context
cfg *settings.Configuration
dbExecutor db.Executor
}
func NewOperationService(ctx context.Context, cfg *settings.Configuration, dbExecutor db.Executor) *OperationService {
return &OperationService{
ctx: ctx,
cfg: cfg,
dbExecutor: dbExecutor,
}
}
func (o *OperationService) Run(ctx context.Context,
cmdArgs *parser.Arguments,
targets []map[string]*dep.InstallInfo,
) error {
if len(targets) == 0 {
fmt.Fprintln(os.Stdout, "", gotext.Get("there is nothing to do"))
return nil
}
preparer := NewPreparer(o.dbExecutor, o.cfg.Runtime.CmdBuilder, o.cfg)
installer := NewInstaller(o.dbExecutor, o.cfg.Runtime.CmdBuilder, o.cfg.Runtime.VCSStore, o.cfg.Runtime.Mode)
pkgBuildDirs, errInstall := preparer.Run(ctx, os.Stdout, targets)
if errInstall != nil {
return errInstall
}
cleanFunc := preparer.ShouldCleanMakeDeps()
if cleanFunc != nil {
installer.AddPostInstallHook(cleanFunc)
}
if cleanAURDirsFunc := preparer.ShouldCleanAURDirs(pkgBuildDirs); cleanAURDirsFunc != nil {
installer.AddPostInstallHook(cleanAURDirsFunc)
}
go func() {
errComp := completion.Update(ctx, o.cfg.Runtime.HTTPClient, o.dbExecutor,
o.cfg.AURURL, o.cfg.Runtime.CompletionPath, o.cfg.CompletionInterval, false)
if errComp != nil {
text.Warnln(errComp)
}
}()
srcInfo, errInstall := srcinfo.NewService(o.dbExecutor, o.cfg, o.cfg.Runtime.CmdBuilder, o.cfg.Runtime.VCSStore, pkgBuildDirs)
if errInstall != nil {
return errInstall
}
incompatible, errInstall := srcInfo.IncompatiblePkgs(ctx)
if errInstall != nil {
return errInstall
}
if errIncompatible := confirmIncompatible(incompatible); errIncompatible != nil {
return errIncompatible
}
if errPGP := srcInfo.CheckPGPKeys(ctx); errPGP != nil {
return errPGP
}
if errInstall := installer.Install(ctx, cmdArgs, targets, pkgBuildDirs); errInstall != nil {
return errInstall
}
var multiErr multierror.MultiError
if err := installer.CompileFailedAndIgnored(); err != nil {
multiErr.Add(err)
}
if err := srcInfo.UpdateVCSStore(ctx, targets, installer.failedAndIgnored); err != nil {
text.Warnln(err)
}
if err := installer.RunPostInstallHooks(ctx); err != nil {
multiErr.Add(err)
}
return multiErr.Return()
}
func confirmIncompatible(incompatible []string) error {
if len(incompatible) > 0 {
text.Warnln(gotext.Get("The following packages are not compatible with your architecture:"))
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
}