forked from Jguer/yay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.go
899 lines (729 loc) · 23.5 KB
/
install.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
package main
import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
alpm "github.com/Jguer/go-alpm/v2"
gosrc "github.com/Morganamilo/go-srcinfo"
mapset "github.com/deckarep/golang-set/v2"
"github.com/leonelquinteros/gotext"
"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"
"github.com/Jguer/yay/v11/pkg/menus"
"github.com/Jguer/yay/v11/pkg/pgp"
"github.com/Jguer/yay/v11/pkg/query"
"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/srcinfo"
"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
}
cmdArgs = cmdArgs.CopyGlobal()
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
}
}
for _, compositePkgName := range pkgs {
pkgSplit := strings.Split(compositePkgName, "/")
pkgName := pkgSplit[0]
if len(pkgSplit) > 1 {
pkgName = pkgSplit[1]
}
cmdArgs.AddTarget(pkgName)
}
if err := cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
cmdArgs, mode, settings.NoConfirm)); err != nil {
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)
}
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)
}
// Install handles package installs.
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")
}
if config.Runtime.Mode.AtLeastRepo() {
if config.CombinedUpgrade {
if refreshArg {
if errR := earlyRefresh(ctx, cmdArgs); errR != nil {
return fmt.Errorf("%s - %w", gotext.Get("error refreshing databases"), errR)
}
}
} else if refreshArg || sysupgradeArg || len(cmdArgs.Targets) > 0 {
if errP := earlyPacmanCall(ctx, cmdArgs, dbExecutor); errP != nil {
return errP
}
}
}
// we may have done -Sy, our handle now has an old
// database.
if errRefresh := dbExecutor.RefreshHandle(); errRefresh != nil {
return errRefresh
}
remoteNames := dbExecutor.InstalledRemotePackageNames()
localNames := dbExecutor.InstalledSyncPackageNames()
remoteNamesCache := mapset.NewThreadUnsafeSet(remoteNames...)
localNamesCache := stringset.FromSlice(localNames)
requestTargets := cmdArgs.Copy().Targets
// create the arguments to pass for the repo install
arguments := cmdArgs.Copy()
arguments.DelArg("asdeps", "asdep")
arguments.DelArg("asexplicit", "asexp")
arguments.Op = "S"
arguments.ClearTargets()
if config.Runtime.Mode == parser.ModeAUR {
arguments.DelArg("u", "sysupgrade")
}
// if we are doing -u also request all packages needing update
if sysupgradeArg {
var errSysUp error
requestTargets, errSysUp = addUpgradeTargetsToArgs(ctx, dbExecutor, cmdArgs, requestTargets, arguments)
if errSysUp != nil {
return errSysUp
}
}
targets := stringset.FromSlice(cmdArgs.Targets)
dp, err := dep.GetPool(ctx, requestTargets,
warnings, dbExecutor, config.Runtime.AURClient, config.Runtime.Mode,
ignoreProviders, settings.NoConfirm, config.Provides, config.ReBuild, config.RequestSplitN, noDeps, noCheck, assumeInstalled)
if err != nil {
return err
}
if errC := dp.CheckMissing(noDeps, noCheck); errC != nil {
return errC
}
if len(dp.Aur) == 0 {
if !config.CombinedUpgrade {
if sysupgradeArg {
fmt.Println(gotext.Get(" there is nothing to do"))
}
return nil
}
cmdArgs.Op = "S"
cmdArgs.DelArg("y", "refresh")
if arguments.ExistsArg("ignore") {
cmdArgs.CreateOrAppendOption("ignore", arguments.GetArgs("ignore")...)
}
return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
}
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 {
arguments.AddTarget(pkg.DB().Name() + "/" + pkg.Name())
}
for _, pkg := range dp.Groups {
arguments.AddTarget(pkg)
}
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
}
do.Print()
fmt.Println()
pkgbuildDirs := make(map[string]string, len(do.Aur))
for _, base := range do.Aur {
dir := filepath.Join(config.BuildDir, base.Pkgbase())
pkgbuildDirs[base.Pkgbase()] = dir
}
if config.CleanAfter {
defer func() {
cleanAfter(ctx, config.Runtime.CmdBuilder, pkgbuildDirs)
}()
}
if do.HasMake() {
switch config.RemoveMake {
case "yes":
defer func() {
err = removeMake(ctx, config.Runtime.CmdBuilder, do.GetMake())
}()
case "no":
break
default:
if text.ContinueTask(os.Stdin, gotext.Get("Remove make dependencies after install?"), false, settings.NoConfirm) {
defer func() {
err = removeMake(ctx, config.Runtime.CmdBuilder, do.GetMake())
}()
}
}
}
if errCleanMenu := menus.Clean(os.Stdout, config.CleanMenu,
pkgbuildDirs,
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))
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, ", "))))
}
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,
cloned, settings.NoConfirm, config.AnswerDiff); errDiffMenu != nil {
if errors.As(errDiffMenu, &settings.ErrUserAbort{}) {
return errDiffMenu
}
text.Errorln(errDiffMenu)
}
if errM := mergePkgbuilds(ctx, config.Runtime.CmdBuilder, pkgbuildDirs); errM != nil {
return errM
}
srcinfos, err = srcinfo.ParseSrcinfoFilesByBase(pkgbuildDirs, true)
if err != nil {
return err
}
if errEditMenu := menus.Edit(os.Stdout, config.EditMenu, pkgbuildDirs,
config.Editor, config.EditorFlags, remoteNamesCache, srcinfos,
settings.NoConfirm, config.AnswerEdit); errEditMenu != nil {
if errors.As(errEditMenu, &settings.ErrUserAbort{}) {
return errEditMenu
}
text.Errorln(errEditMenu)
}
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 {
return errCPK
}
}
if !config.CombinedUpgrade {
arguments.DelArg("u", "sysupgrade")
}
if len(arguments.Targets) > 0 || arguments.ExistsArg("u") {
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"))
}
deps := make([]string, 0)
exp := make([]string, 0)
for _, pkg := range do.Repo {
if !dp.Explicit.Get(pkg.Name()) && !localNamesCache.Get(pkg.Name()) && !remoteNamesCache.Contains(pkg.Name()) {
deps = append(deps, pkg.Name())
continue
}
if cmdArgs.ExistsArg("asdeps", "asdep") && dp.Explicit.Get(pkg.Name()) {
deps = append(deps, pkg.Name())
} else if cmdArgs.ExistsArg("asexp", "asexplicit") && dp.Explicit.Get(pkg.Name()) {
exp = append(exp, pkg.Name())
}
}
if errDeps := asdeps(ctx, config.Runtime.CmdBuilder, config.Runtime.Mode, cmdArgs, deps); errDeps != nil {
return errDeps
}
if errExp := asexp(ctx, config.Runtime.CmdBuilder, config.Runtime.Mode, cmdArgs, exp); errExp != nil {
return errExp
}
}
go func() {
_ = completion.Update(ctx, config.Runtime.HTTPClient, dbExecutor,
config.AURURL, config.Runtime.CompletionPath, config.CompletionInterval, false)
}()
if errP := downloadPKGBUILDSourceFanout(ctx,
config.Runtime.CmdBuilder,
pkgbuildDirs,
true, config.MaxConcurrentDownloads); errP != nil {
text.Errorln(errP)
}
if errB := buildInstallPkgbuilds(ctx, cmdArgs, dbExecutor, dp, do, srcinfos, true, conflicts, noDeps, noCheck); errB != nil {
return errB
}
return nil
}
func addUpgradeTargetsToArgs(ctx context.Context, dbExecutor db.Executor,
cmdArgs *parser.Arguments, requestTargets []string, arguments *parser.Arguments,
) ([]string, error) {
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()...)
}
return requestTargets, nil
}
func removeMake(ctx context.Context, cmdBuilder exe.ICmdBuilder, makeDeps []string) error {
removeArguments := parser.MakeArguments()
err := removeArguments.AddArg("R", "u")
if err != nil {
return err
}
for _, pkg := range makeDeps {
removeArguments.AddTarget(pkg)
}
oldValue := settings.NoConfirm
settings.NoConfirm = true
err = cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
removeArguments, config.Runtime.Mode, settings.NoConfirm))
settings.NoConfirm = oldValue
return err
}
func inRepos(dbExecutor db.Executor, pkg string) bool {
target := dep.ToTarget(pkg)
if target.DB == "aur" {
return false
} else if target.DB != "" {
return true
}
previousHideMenus := settings.HideMenus
settings.HideMenus = true
exists := dbExecutor.SyncSatisfierExists(target.DepString())
settings.HideMenus = previousHideMenus
return exists || len(dbExecutor.PackagesFromGroup(target.Name)) > 0
}
func earlyPacmanCall(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
arguments := cmdArgs.Copy()
arguments.Op = "S"
targets := cmdArgs.Targets
cmdArgs.ClearTargets()
arguments.ClearTargets()
if config.Runtime.Mode == parser.ModeRepo {
arguments.Targets = targets
} else {
// separate aur and repo targets
for _, target := range targets {
if inRepos(dbExecutor, target) {
arguments.AddTarget(target)
} else {
cmdArgs.AddTarget(target)
}
}
}
if cmdArgs.ExistsArg("y", "refresh") || cmdArgs.ExistsArg("u", "sysupgrade") || len(arguments.Targets) > 0 {
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"))
}
}
return nil
}
func earlyRefresh(ctx context.Context, cmdArgs *parser.Arguments) error {
arguments := cmdArgs.Copy()
cmdArgs.DelArg("y", "refresh")
arguments.DelArg("u", "sysupgrade")
arguments.DelArg("s", "search")
arguments.DelArg("i", "info")
arguments.DelArg("l", "list")
arguments.ClearTargets()
return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
arguments, config.Runtime.Mode, settings.NoConfirm))
}
func confirmIncompatibleInstall(srcinfos map[string]*gosrc.Srcinfo, dbExecutor db.Executor) error {
incompatible := []string{}
alpmArch, err := dbExecutor.AlpmArchitectures()
if err != nil {
return err
}
nextpkg:
for base, srcinfo := range srcinfos {
for _, arch := range srcinfo.Arch {
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:"))
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 %w", 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 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
}
}
return nil
}
func buildInstallPkgbuilds(
ctx context.Context,
cmdArgs *parser.Arguments,
dbExecutor db.Executor,
dp *dep.Pool,
do *dep.Order,
srcinfos map[string]*gosrc.Srcinfo,
incompatible bool,
conflicts stringset.MapStringSet, noDeps, noCheck bool,
) error {
deps := make([]string, 0)
exp := make([]string, 0)
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 {
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)
deps = make([]string, 0)
exp = make([]string, 0)
pkgArchives = make([]string, 0) // reset the pkgarchives
if errArchive != nil || errReason != nil {
if i != 0 {
go config.Runtime.VCSStore.RemovePackages([]string{do.Aur[i-1].String()})
}
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(
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)
}
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
}
if cmdArgs.ExistsArg("needed") {
installed := true
for _, split := range base {
installed = dp.AlpmExecutor.IsCorrectVersionInstalled(split.Name, pkgVersion)
}
if installed {
err := config.Runtime.CmdBuilder.Show(
config.Runtime.CmdBuilder.BuildMakepkgCmd(ctx,
dir, "-c", "--nobuild", "--noextract", "--ignorearch"))
if err != nil {
return errors.New(gotext.Get("error making: %s", err))
}
fmt.Fprintln(os.Stdout, gotext.Get("%s is up to date -- skipping", text.Cyan(pkg+"-"+pkgVersion)))
continue
}
}
if built {
err := config.Runtime.CmdBuilder.Show(
config.Runtime.CmdBuilder.BuildMakepkgCmd(ctx,
dir, "-c", "--nobuild", "--noextract", "--ignorearch"))
if err != nil {
return errors.New(gotext.Get("error making: %s", err))
}
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(
config.Runtime.CmdBuilder.BuildMakepkgCmd(ctx,
dir, args...)); errMake != nil {
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
break
}
}
}
var errAdd error
for _, split := range base {
for suffix, optional := range map[string]bool{"": false, "-debug": true} {
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
for _, pkg := range base {
if srcInfo == nil {
text.Errorln(gotext.Get("could not find srcinfo for: %s", pkg.Name))
break
}
wg.Add(1)
text.Debugln("checking vcs store for:", pkg.Name)
go func(name string) {
config.Runtime.VCSStore.Update(ctx, name, srcInfo.Source)
wg.Done()
}(pkg.Name)
}
wg.Wait()
}
text.Debugln("installing archives:", pkgArchives)
errArchive := installPkgArchive(ctx, config.Runtime.CmdBuilder, config.Runtime.Mode, config.Runtime.VCSStore, cmdArgs, pkgArchives)
if errArchive != nil {
go config.Runtime.VCSStore.RemovePackages([]string{do.Aur[len(do.Aur)-1].String()})
}
errReason := setInstallReason(ctx, config.Runtime.CmdBuilder, config.Runtime.Mode, cmdArgs, deps, exp)
if errReason != nil {
go config.Runtime.VCSStore.RemovePackages([]string{do.Aur[len(do.Aur)-1].String()})
}
settings.NoConfirm = oldConfirm
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
}
arguments := cmdArgs.Copy()
arguments.ClearTargets()
arguments.Op = "U"
arguments.DelArg("confirm")
arguments.DelArg("noconfirm")
arguments.DelArg("c", "clean")
arguments.DelArg("i", "install")
arguments.DelArg("q", "quiet")
arguments.DelArg("y", "refresh")
arguments.DelArg("u", "sysupgrade")
arguments.DelArg("w", "downloadonly")
arguments.DelArg("asdeps", "asdep")
arguments.DelArg("asexplicit", "asexp")
arguments.AddTarget(pkgArchives...)
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)
}
return nil
}
func setInstallReason(ctx context.Context,
cmdBuilder exe.ICmdBuilder, mode parser.TargetMode,
cmdArgs *parser.Arguments, deps, exps []string,
) error {
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,
cmdArgs *parser.Arguments, pkgdests map[string]string,
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 {
return deps, exp, pkgArchives, nil
}
return deps, exp, pkgArchives, &FindPkgDestError{pkgDest: pkgdest, name: name}
}
pkgArchives = append(pkgArchives, pkgdest)
switch {
case cmdArgs.ExistsArg("asdeps", "asdep"):
deps = append(deps, name)
case cmdArgs.ExistsArg("asexplicit", "asexp"):
exp = append(exp, name)
case !dp.Explicit.Get(name) && !localNamesCache.Get(name) && !remoteNamesCache.Get(name):
deps = append(deps, name)
default:
exp = append(exp, name)
}
return deps, exp, pkgArchives, nil
}