fix(vcs): do not vcs update gather orphan info (#1902)

* reduce complexity of devel upgrade gathering

* clean orphans devel
This commit is contained in:
Jo 2023-01-23 23:03:32 +00:00 committed by GitHub
parent 1bfbd01f94
commit 4626a0409c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 157 additions and 82 deletions

2
cmd.go
View File

@ -383,7 +383,7 @@ func handleRemove(ctx context.Context, cmdArgs *parser.Arguments, localCache vcs
err := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx, err := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
cmdArgs, config.Runtime.Mode, settings.NoConfirm)) cmdArgs, config.Runtime.Mode, settings.NoConfirm))
if err == nil { if err == nil {
localCache.RemovePackage(cmdArgs.Targets) localCache.RemovePackages(cmdArgs.Targets)
} }
return err return err

View File

@ -648,7 +648,7 @@ func buildInstallPkgbuilds(
if errArchive != nil || errReason != nil { if errArchive != nil || errReason != nil {
if i != 0 { if i != 0 {
go config.Runtime.VCSStore.RemovePackage([]string{do.Aur[i-1].String()}) go config.Runtime.VCSStore.RemovePackages([]string{do.Aur[i-1].String()})
} }
if errArchive != nil { if errArchive != nil {
@ -794,12 +794,12 @@ func buildInstallPkgbuilds(
text.Debugln("installing archives:", pkgArchives) text.Debugln("installing archives:", pkgArchives)
errArchive := installPkgArchive(ctx, config.Runtime.CmdBuilder, config.Runtime.Mode, config.Runtime.VCSStore, cmdArgs, pkgArchives) errArchive := installPkgArchive(ctx, config.Runtime.CmdBuilder, config.Runtime.Mode, config.Runtime.VCSStore, cmdArgs, pkgArchives)
if errArchive != nil { if errArchive != nil {
go config.Runtime.VCSStore.RemovePackage([]string{do.Aur[len(do.Aur)-1].String()}) 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) errReason := setInstallReason(ctx, config.Runtime.CmdBuilder, config.Runtime.Mode, cmdArgs, deps, exp)
if errReason != nil { if errReason != nil {
go config.Runtime.VCSStore.RemovePackage([]string{do.Aur[len(do.Aur)-1].String()}) go config.Runtime.VCSStore.RemovePackages([]string{do.Aur[len(do.Aur)-1].String()})
} }
settings.NoConfirm = oldConfirm settings.NoConfirm = oldConfirm

View File

@ -31,7 +31,7 @@ type Executor interface {
BiggestPackages() []IPackage BiggestPackages() []IPackage
Cleanup() Cleanup()
InstalledRemotePackageNames() []string InstalledRemotePackageNames() []string
InstalledRemotePackages() []IPackage InstalledRemotePackages() map[string]IPackage
InstalledSyncPackageNames() []string InstalledSyncPackageNames() []string
IsCorrectVersionInstalled(string, string) bool IsCorrectVersionInstalled(string, string) bool
LastBuildTime() time.Time LastBuildTime() time.Time

View File

@ -24,8 +24,8 @@ type AlpmExecutor struct {
syncDBsCache []alpm.IDB syncDBsCache []alpm.IDB
conf *pacmanconf.Config conf *pacmanconf.Config
installedRemotePkgs []alpm.IPackage
installedRemotePkgNames []string installedRemotePkgNames []string
installedRemotePkgMap map[string]alpm.IPackage
installedSyncPkgNames []string installedSyncPkgNames []string
} }
@ -36,8 +36,8 @@ func NewExecutor(pacmanConf *pacmanconf.Config) (*AlpmExecutor, error) {
syncDB: nil, syncDB: nil,
syncDBsCache: []alpm.IDB{}, syncDBsCache: []alpm.IDB{},
conf: pacmanConf, conf: pacmanConf,
installedRemotePkgs: nil,
installedRemotePkgNames: nil, installedRemotePkgNames: nil,
installedRemotePkgMap: map[string]alpm.IPackage{},
installedSyncPkgNames: nil, installedSyncPkgNames: nil,
} }

View File

@ -1,7 +1,8 @@
package ialpm package ialpm
import ( import (
"github.com/Jguer/yay/v11/pkg/db" alpm "github.com/Jguer/go-alpm/v2"
"github.com/Jguer/yay/v11/pkg/text" "github.com/Jguer/yay/v11/pkg/text"
) )
@ -12,8 +13,8 @@ func (ae *AlpmExecutor) getPackageNamesBySource() {
if ae.SyncPackage(pkgName) != nil { if ae.SyncPackage(pkgName) != nil {
ae.installedSyncPkgNames = append(ae.installedSyncPkgNames, pkgName) ae.installedSyncPkgNames = append(ae.installedSyncPkgNames, pkgName)
} else { } else {
ae.installedRemotePkgs = append(ae.installedRemotePkgs, localpkg)
ae.installedRemotePkgNames = append(ae.installedRemotePkgNames, pkgName) ae.installedRemotePkgNames = append(ae.installedRemotePkgNames, pkgName)
ae.installedRemotePkgMap[pkgName] = localpkg
} }
} }
@ -21,12 +22,12 @@ func (ae *AlpmExecutor) getPackageNamesBySource() {
"sync_len", len(ae.installedSyncPkgNames), "remote_len", len(ae.installedRemotePkgNames)) "sync_len", len(ae.installedSyncPkgNames), "remote_len", len(ae.installedRemotePkgNames))
} }
func (ae *AlpmExecutor) InstalledRemotePackages() []db.IPackage { func (ae *AlpmExecutor) InstalledRemotePackages() map[string]alpm.IPackage {
if ae.installedRemotePkgs == nil { if ae.installedRemotePkgMap == nil {
ae.getPackageNamesBySource() ae.getPackageNamesBySource()
} }
return ae.installedRemotePkgs return ae.installedRemotePkgMap
} }
func (ae *AlpmExecutor) InstalledRemotePackageNames() []string { func (ae *AlpmExecutor) InstalledRemotePackageNames() []string {

View File

@ -13,31 +13,25 @@ import (
func UpDevel( func UpDevel(
ctx context.Context, ctx context.Context,
remote []db.IPackage, // should be a map remote map[string]db.IPackage,
aurdata map[string]*query.Pkg, aurdata map[string]*query.Pkg,
localCache vcs.Store, localCache vcs.Store,
) UpSlice { ) UpSlice {
toUpdate := make([]db.IPackage, 0, len(aurdata))
toRemove := make([]string, 0) toRemove := make([]string, 0)
toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"devel"}}
for _, pkgName := range localCache.ToUpgrade(ctx) { for pkgName, pkg := range remote {
if _, ok := aurdata[pkgName]; ok { if localCache.ToUpgrade(ctx, pkgName) {
for _, pkg := range remote { if _, ok := aurdata[pkgName]; !ok {
if pkg.Name() == pkgName { text.Warnln(gotext.Get("ignoring package devel upgrade (no AUR info found):"), pkgName)
toUpdate = append(toUpdate, pkg) continue
}
} }
} else {
toRemove = append(toRemove, pkgName)
}
}
toUpgrade := UpSlice{Up: make([]Upgrade, 0, len(toUpdate)), Repos: []string{"devel"}} if pkg.ShouldIgnore() {
printIgnoringPackage(pkg, "latest-commit")
continue
}
for _, pkg := range toUpdate {
if pkg.ShouldIgnore() {
printIgnoringPackage(pkg, "latest-commit")
} else {
toUpgrade.Up = append(toUpgrade.Up, toUpgrade.Up = append(toUpgrade.Up,
Upgrade{ Upgrade{
Name: pkg.Name(), Name: pkg.Name(),
@ -50,7 +44,7 @@ func UpDevel(
} }
} }
localCache.RemovePackage(toRemove) localCache.RemovePackages(toRemove)
return toUpgrade return toUpgrade
} }
@ -66,11 +60,11 @@ func printIgnoringPackage(pkg db.IPackage, newPkgVersion string) {
// UpAUR gathers foreign packages and checks if they have new versions. // UpAUR gathers foreign packages and checks if they have new versions.
// Output: Upgrade type package list. // Output: Upgrade type package list.
func UpAUR(remote []db.IPackage, aurdata map[string]*query.Pkg, timeUpdate bool) UpSlice { func UpAUR(remote map[string]db.IPackage, aurdata map[string]*query.Pkg, timeUpdate bool) UpSlice {
toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"aur"}} toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"aur"}}
for _, pkg := range remote { for name, pkg := range remote {
aurPkg, ok := aurdata[pkg.Name()] aurPkg, ok := aurdata[name]
if !ok { if !ok {
continue continue
} }

View File

@ -18,7 +18,7 @@ func Test_upAUR(t *testing.T) {
t.Parallel() t.Parallel()
type args struct { type args struct {
remote []alpm.IPackage remote map[string]alpm.IPackage
aurdata map[string]*aur.Pkg aurdata map[string]*aur.Pkg
timeUpdate bool timeUpdate bool
} }
@ -30,10 +30,10 @@ func Test_upAUR(t *testing.T) {
{ {
name: "No Updates", name: "No Updates",
args: args{ args: args{
remote: []alpm.IPackage{ remote: map[string]alpm.IPackage{
&mock.Package{PName: "hello", PVersion: "2.0.0"}, "hello": &mock.Package{PName: "hello", PVersion: "2.0.0"},
&mock.Package{PName: "local_pkg", PVersion: "1.1.0"}, "local_pkg": &mock.Package{PName: "local_pkg", PVersion: "1.1.0"},
&mock.Package{PName: "ignored", PVersion: "1.0.0", PShouldIgnore: true}, "ignored": &mock.Package{PName: "ignored", PVersion: "1.0.0", PShouldIgnore: true},
}, },
aurdata: map[string]*aur.Pkg{ aurdata: map[string]*aur.Pkg{
"hello": {Version: "2.0.0", Name: "hello"}, "hello": {Version: "2.0.0", Name: "hello"},
@ -46,7 +46,9 @@ func Test_upAUR(t *testing.T) {
{ {
name: "Simple Update", name: "Simple Update",
args: args{ args: args{
remote: []alpm.IPackage{&mock.Package{PName: "hello", PVersion: "2.0.0"}}, remote: map[string]alpm.IPackage{
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0"},
},
aurdata: map[string]*aur.Pkg{"hello": {Version: "2.1.0", Name: "hello"}}, aurdata: map[string]*aur.Pkg{"hello": {Version: "2.1.0", Name: "hello"}},
timeUpdate: false, timeUpdate: false,
}, },
@ -55,7 +57,9 @@ func Test_upAUR(t *testing.T) {
{ {
name: "Time Update", name: "Time Update",
args: args{ args: args{
remote: []alpm.IPackage{&mock.Package{PName: "hello", PVersion: "2.0.0", PBuildDate: time.Now()}}, remote: map[string]alpm.IPackage{
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0", PBuildDate: time.Now()},
},
aurdata: map[string]*aur.Pkg{"hello": {Version: "2.0.0", Name: "hello", LastModified: int(time.Now().AddDate(0, 0, 2).Unix())}}, aurdata: map[string]*aur.Pkg{"hello": {Version: "2.0.0", Name: "hello", LastModified: int(time.Now().AddDate(0, 0, 2).Unix())}},
timeUpdate: true, timeUpdate: true,
}, },
@ -66,6 +70,7 @@ func Test_upAUR(t *testing.T) {
tt := tt tt := tt
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
t.Parallel() t.Parallel()
got := UpAUR(tt.args.remote, tt.args.aurdata, tt.args.timeUpdate) got := UpAUR(tt.args.remote, tt.args.aurdata, tt.args.timeUpdate)
assert.EqualValues(t, tt.want, got) assert.EqualValues(t, tt.want, got)
}) })
@ -76,7 +81,7 @@ func Test_upDevel(t *testing.T) {
t.Parallel() t.Parallel()
type args struct { type args struct {
remote []alpm.IPackage remote map[string]alpm.IPackage
aurdata map[string]*aur.Pkg aurdata map[string]*aur.Pkg
cached vcs.Store cached vcs.Store
} }
@ -90,10 +95,10 @@ func Test_upDevel(t *testing.T) {
name: "No Updates", name: "No Updates",
args: args{ args: args{
cached: &vcs.Mock{}, cached: &vcs.Mock{},
remote: []alpm.IPackage{ remote: map[string]alpm.IPackage{
&mock.Package{PName: "hello", PVersion: "2.0.0"}, "hello": &mock.Package{PName: "hello", PVersion: "2.0.0"},
&mock.Package{PName: "local_pkg", PVersion: "1.1.0"}, "local_pkg": &mock.Package{PName: "local_pkg", PVersion: "1.1.0"},
&mock.Package{PName: "ignored", PVersion: "1.0.0", PShouldIgnore: true}, "ignored": &mock.Package{PName: "ignored", PVersion: "1.0.0", PShouldIgnore: true},
}, },
aurdata: map[string]*aur.Pkg{ aurdata: map[string]*aur.Pkg{
"hello": {Version: "2.0.0", Name: "hello"}, "hello": {Version: "2.0.0", Name: "hello"},
@ -109,10 +114,10 @@ func Test_upDevel(t *testing.T) {
cached: &vcs.Mock{ cached: &vcs.Mock{
ToUpgradeReturn: []string{"hello", "hello4"}, ToUpgradeReturn: []string{"hello", "hello4"},
}, },
remote: []alpm.IPackage{ remote: map[string]alpm.IPackage{
&mock.Package{PName: "hello", PVersion: "2.0.0"}, "hello": &mock.Package{PName: "hello", PVersion: "2.0.0"},
&mock.Package{PName: "hello2", PVersion: "3.0.0"}, "hello2": &mock.Package{PName: "hello2", PVersion: "3.0.0"},
&mock.Package{PName: "hello4", PVersion: "4.0.0"}, "hello4": &mock.Package{PName: "hello4", PVersion: "4.0.0"},
}, },
aurdata: map[string]*aur.Pkg{ aurdata: map[string]*aur.Pkg{
"hello": {Version: "2.0.0", Name: "hello"}, "hello": {Version: "2.0.0", Name: "hello"},
@ -141,8 +146,10 @@ func Test_upDevel(t *testing.T) {
name: "No update returned", name: "No update returned",
finalLen: 1, finalLen: 1,
args: args{ args: args{
cached: &vcs.Mock{ToUpgradeReturn: []string{}}, cached: &vcs.Mock{ToUpgradeReturn: []string{}},
remote: []alpm.IPackage{&mock.Package{PName: "hello", PVersion: "2.0.0"}}, remote: map[string]alpm.IPackage{
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0"},
},
aurdata: map[string]*aur.Pkg{"hello": {Version: "2.0.0", Name: "hello"}}, aurdata: map[string]*aur.Pkg{"hello": {Version: "2.0.0", Name: "hello"}},
}, },
want: UpSlice{Repos: []string{"devel"}}, want: UpSlice{Repos: []string{"devel"}},
@ -154,7 +161,9 @@ func Test_upDevel(t *testing.T) {
cached: &vcs.Mock{ cached: &vcs.Mock{
ToUpgradeReturn: []string{"hello"}, ToUpgradeReturn: []string{"hello"},
}, },
remote: []alpm.IPackage{&mock.Package{PName: "hello", PVersion: "2.0.0", PShouldIgnore: true}}, remote: map[string]alpm.IPackage{
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0", PShouldIgnore: true},
},
aurdata: map[string]*aur.Pkg{"hello": {Version: "2.0.0", Name: "hello"}}, aurdata: map[string]*aur.Pkg{"hello": {Version: "2.0.0", Name: "hello"}},
}, },
want: UpSlice{Repos: []string{"devel"}}, want: UpSlice{Repos: []string{"devel"}},

View File

@ -3,6 +3,7 @@ package vcs
import ( import (
"context" "context"
"github.com/Jguer/go-alpm/v2"
gosrc "github.com/Morganamilo/go-srcinfo" gosrc "github.com/Morganamilo/go-srcinfo"
) )
@ -11,8 +12,13 @@ type Mock struct {
ToUpgradeReturn []string ToUpgradeReturn []string
} }
func (m *Mock) ToUpgrade(ctx context.Context) []string { func (m *Mock) ToUpgrade(ctx context.Context, pkgName string) bool {
return m.ToUpgradeReturn for _, pkg := range m.ToUpgradeReturn {
if pkg == pkgName {
return true
}
}
return false
} }
func (m *Mock) Update(ctx context.Context, pkgName string, sources []gosrc.ArchString) { func (m *Mock) Update(ctx context.Context, pkgName string, sources []gosrc.ArchString) {
@ -22,9 +28,12 @@ func (m *Mock) Save() error {
return nil return nil
} }
func (m *Mock) RemovePackage(pkgs []string) { func (m *Mock) RemovePackages(pkgs []string) {
} }
func (m *Mock) Load() error { func (m *Mock) Load() error {
return nil return nil
} }
func (m *Mock) CleanOrphans(pkgs map[string]alpm.IPackage) {
}

View File

@ -11,6 +11,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/Jguer/go-alpm/v2"
gosrc "github.com/Morganamilo/go-srcinfo" gosrc "github.com/Morganamilo/go-srcinfo"
"github.com/leonelquinteros/gotext" "github.com/leonelquinteros/gotext"
@ -19,16 +20,18 @@ import (
) )
type Store interface { type Store interface {
// ToUpgrade returns a list of packages that need to be updated. // ToUpgrade returns true if the package needs to be updated.
ToUpgrade(ctx context.Context) []string ToUpgrade(ctx context.Context, pkgName string) bool
// Update updates the VCS info of a package. // Update updates the VCS info of a package.
Update(ctx context.Context, pkgName string, sources []gosrc.ArchString) Update(ctx context.Context, pkgName string, sources []gosrc.ArchString)
// Save saves the VCS info to disk. // RemovePackages removes the VCS info of the packages given as arg if they exist.
Save() error RemovePackages(pkgs []string)
// RemovePackage removes the VCS info of a package. // Clean orphaned VCS info.
RemovePackage(pkgs []string) CleanOrphans(pkgs map[string]alpm.IPackage)
// Load loads the VCS info from disk. // Load loads the VCS info from disk.
Load() error Load() error
// Save saves the VCS info to disk.
Save() error
} }
// InfoStore is a collection of OriginInfoByURL by Package. // InfoStore is a collection of OriginInfoByURL by Package.
@ -200,15 +203,12 @@ func parseSource(source string) (url, branch string, protocols []string) {
return url, branch, protocols return url, branch, protocols
} }
func (v *InfoStore) ToUpgrade(ctx context.Context) []string { func (v *InfoStore) ToUpgrade(ctx context.Context, pkgName string) bool {
pkgs := make([]string, 0, len(v.OriginsByPackage)) if infos, ok := v.OriginsByPackage[pkgName]; ok {
for pkgName, infos := range v.OriginsByPackage { return v.needsUpdate(ctx, infos)
if v.needsUpdate(ctx, infos) {
pkgs = append(pkgs, pkgName)
}
} }
return pkgs return false
} }
func (v *InfoStore) needsUpdate(ctx context.Context, infos OriginInfoByURL) bool { func (v *InfoStore) needsUpdate(ctx context.Context, infos OriginInfoByURL) bool {
@ -278,7 +278,7 @@ func (v *InfoStore) Save() error {
} }
// RemovePackage removes package from VCS information. // RemovePackage removes package from VCS information.
func (v *InfoStore) RemovePackage(pkgs []string) { func (v *InfoStore) RemovePackages(pkgs []string) {
updated := false updated := false
for _, pkgName := range pkgs { for _, pkgName := range pkgs {
@ -314,3 +314,16 @@ func (v *InfoStore) Load() error {
return nil return nil
} }
func (v *InfoStore) CleanOrphans(pkgs map[string]alpm.IPackage) {
missing := make([]string, 0)
for pkgName := range v.OriginsByPackage {
if _, ok := pkgs[pkgName]; !ok {
text.Debugln("removing orphaned vcs package:", pkgName)
missing = append(missing, pkgName)
}
}
v.RemovePackages(missing)
}

View File

@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/settings/exe" "github.com/Jguer/yay/v11/pkg/settings/exe"
) )
@ -113,7 +114,7 @@ func TestInfoStoreToUpgrade(t *testing.T) {
name string name string
fields fields fields fields
args args args args
want []string want bool
}{ }{
{ {
name: "simple-has_update", name: "simple-has_update",
@ -128,7 +129,7 @@ func TestInfoStoreToUpgrade(t *testing.T) {
Returned: []string{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa HEAD"}, Returned: []string{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa HEAD"},
}}, }},
}, },
want: []string{"yay"}, want: true,
}, },
{ {
name: "double-has_update", name: "double-has_update",
@ -151,7 +152,7 @@ func TestInfoStoreToUpgrade(t *testing.T) {
}, },
}}, }},
}, },
want: []string{"yay"}, want: true,
}, },
{ {
name: "simple-no_update", name: "simple-no_update",
@ -166,7 +167,7 @@ func TestInfoStoreToUpgrade(t *testing.T) {
Returned: []string{"991c5b4146fd27f4aacf4e3111258a848934aaa1 HEAD"}, Returned: []string{"991c5b4146fd27f4aacf4e3111258a848934aaa1 HEAD"},
}}, }},
}, },
want: []string{}, want: false,
}, },
{ {
name: "simple-no_split", name: "simple-no_split",
@ -181,7 +182,7 @@ func TestInfoStoreToUpgrade(t *testing.T) {
Returned: []string{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, Returned: []string{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
}}, }},
}, },
want: []string{}, want: false,
}, },
{ {
name: "simple-error", name: "simple-error",
@ -199,7 +200,7 @@ func TestInfoStoreToUpgrade(t *testing.T) {
}, },
}, },
}, },
want: []string{}, want: false,
}, },
{ {
name: "simple-no protocol", name: "simple-no protocol",
@ -214,7 +215,7 @@ func TestInfoStoreToUpgrade(t *testing.T) {
Returned: []string{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, Returned: []string{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
}}, }},
}, },
want: []string{}, want: false,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
@ -227,7 +228,7 @@ func TestInfoStoreToUpgrade(t *testing.T) {
"yay": tt.args.infos, "yay": tt.args.infos,
}, },
} }
got := v.ToUpgrade(context.Background()) got := v.ToUpgrade(context.Background(), "yay")
assert.Equal(t, tt.want, got) assert.Equal(t, tt.want, got)
}) })
} }
@ -468,10 +469,57 @@ func TestInfoStore_Remove(t *testing.T) {
OriginsByPackage: tt.fields.OriginsByPackage, OriginsByPackage: tt.fields.OriginsByPackage,
FilePath: filePath, FilePath: filePath,
} }
v.RemovePackage(tt.args.pkgs) v.RemovePackages(tt.args.pkgs)
assert.Len(t, tt.fields.OriginsByPackage, 2) assert.Len(t, tt.fields.OriginsByPackage, 2)
}) })
} }
require.NoError(t, os.Remove(filePath)) require.NoError(t, os.Remove(filePath))
} }
func TestInfoStore_CleanOrphans(t *testing.T) {
t.Parallel()
type fields struct {
OriginsByPackage map[string]OriginInfoByURL
}
type args struct {
pkgs map[string]db.IPackage
}
tests := []struct {
name string
fields fields
args args
}{
{
name: "simple",
args: args{pkgs: map[string]db.IPackage{"a": nil, "b": nil, "d": nil}},
fields: fields{
OriginsByPackage: map[string]OriginInfoByURL{
"a": {},
"b": {},
"c": {},
"d": {},
},
},
},
}
file, err := os.CreateTemp("/tmp", "yay-vcs-*-test")
filePath := file.Name()
require.NoError(t, err)
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
v := &InfoStore{
OriginsByPackage: tt.fields.OriginsByPackage,
FilePath: filePath,
}
v.CleanOrphans(tt.args.pkgs)
assert.Len(t, tt.fields.OriginsByPackage, 3)
})
}
require.NoError(t, os.Remove(filePath))
}

View File

@ -103,6 +103,7 @@ func upList(ctx context.Context, aurCache settings.AURCache,
go func() { go func() {
develUp = upgrade.UpDevel(ctx, remote, aurdata, config.Runtime.VCSStore) develUp = upgrade.UpDevel(ctx, remote, aurdata, config.Runtime.VCSStore)
config.Runtime.VCSStore.CleanOrphans(remote)
wg.Done() wg.Done()
}() }()
} }
@ -137,10 +138,10 @@ func upList(ctx context.Context, aurCache settings.AURCache,
} }
func printLocalNewerThanAUR( func printLocalNewerThanAUR(
remote []alpm.IPackage, aurdata map[string]*aur.Pkg, remote map[string]alpm.IPackage, aurdata map[string]*aur.Pkg,
) { ) {
for _, pkg := range remote { for name, pkg := range remote {
aurPkg, ok := aurdata[pkg.Name()] aurPkg, ok := aurdata[name]
if !ok { if !ok {
continue continue
} }
@ -149,7 +150,7 @@ func printLocalNewerThanAUR(
if !isDevelPackage(pkg) && db.VerCmp(pkg.Version(), aurPkg.Version) > 0 { if !isDevelPackage(pkg) && db.VerCmp(pkg.Version(), aurPkg.Version) > 0 {
text.Warnln(gotext.Get("%s: local (%s) is newer than AUR (%s)", text.Warnln(gotext.Get("%s: local (%s) is newer than AUR (%s)",
text.Cyan(pkg.Name()), text.Cyan(name),
left, right, left, right,
)) ))
} }