sources.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package upgrade
  2. import (
  3. "context"
  4. "sync"
  5. "github.com/leonelquinteros/gotext"
  6. "github.com/Jguer/yay/v11/pkg/db"
  7. "github.com/Jguer/yay/v11/pkg/query"
  8. "github.com/Jguer/yay/v11/pkg/text"
  9. "github.com/Jguer/yay/v11/pkg/vcs"
  10. )
  11. func UpDevel(
  12. ctx context.Context,
  13. remote []db.IPackage,
  14. aurdata map[string]*query.Pkg,
  15. localCache *vcs.InfoStore,
  16. ) UpSlice {
  17. toUpdate := make([]db.IPackage, 0, len(aurdata))
  18. toRemove := make([]string, 0)
  19. var (
  20. mux1, mux2 sync.Mutex
  21. wg sync.WaitGroup
  22. )
  23. checkUpdate := func(pkgName string, e vcs.OriginInfoByURL) {
  24. defer wg.Done()
  25. if localCache.NeedsUpdate(ctx, e) {
  26. if _, ok := aurdata[pkgName]; ok {
  27. for _, pkg := range remote {
  28. if pkg.Name() == pkgName {
  29. mux1.Lock()
  30. toUpdate = append(toUpdate, pkg)
  31. mux1.Unlock()
  32. return
  33. }
  34. }
  35. }
  36. mux2.Lock()
  37. toRemove = append(toRemove, pkgName)
  38. mux2.Unlock()
  39. }
  40. }
  41. for pkgName, e := range localCache.OriginsByPackage {
  42. wg.Add(1)
  43. go checkUpdate(pkgName, e)
  44. }
  45. wg.Wait()
  46. toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"devel"}}
  47. for _, pkg := range toUpdate {
  48. if pkg.ShouldIgnore() {
  49. printIgnoringPackage(pkg, "latest-commit")
  50. } else {
  51. toUpgrade.Up = append(toUpgrade.Up,
  52. Upgrade{
  53. Name: pkg.Name(),
  54. Base: pkg.Base(),
  55. Repository: "devel",
  56. LocalVersion: pkg.Version(),
  57. RemoteVersion: "latest-commit",
  58. Reason: pkg.Reason(),
  59. })
  60. }
  61. }
  62. localCache.RemovePackage(toRemove)
  63. return toUpgrade
  64. }
  65. func printIgnoringPackage(pkg db.IPackage, newPkgVersion string) {
  66. left, right := GetVersionDiff(pkg.Version(), newPkgVersion)
  67. text.Warnln(gotext.Get("%s: ignoring package upgrade (%s => %s)",
  68. text.Cyan(pkg.Name()),
  69. left, right,
  70. ))
  71. }
  72. // UpAUR gathers foreign packages and checks if they have new versions.
  73. // Output: Upgrade type package list.
  74. func UpAUR(remote []db.IPackage, aurdata map[string]*query.Pkg, timeUpdate bool) UpSlice {
  75. toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"aur"}}
  76. for _, pkg := range remote {
  77. aurPkg, ok := aurdata[pkg.Name()]
  78. if !ok {
  79. continue
  80. }
  81. if (timeUpdate && (int64(aurPkg.LastModified) > pkg.BuildDate().Unix())) ||
  82. (db.VerCmp(pkg.Version(), aurPkg.Version) < 0) {
  83. if pkg.ShouldIgnore() {
  84. printIgnoringPackage(pkg, aurPkg.Version)
  85. } else {
  86. toUpgrade.Up = append(toUpgrade.Up,
  87. Upgrade{
  88. Name: aurPkg.Name,
  89. Base: aurPkg.PackageBase,
  90. Repository: "aur",
  91. LocalVersion: pkg.Version(),
  92. RemoteVersion: aurPkg.Version,
  93. Reason: pkg.Reason(),
  94. })
  95. }
  96. }
  97. }
  98. return toUpgrade
  99. }