sources.go 2.5 KB

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