fix(yay): check if downgrade has smaller version (#2054)

This commit is contained in:
Jo 2023-04-03 17:37:41 +01:00 committed by GitHub
parent 3f09397816
commit ada8261bca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 10 deletions

View File

@ -73,14 +73,14 @@ func (u *UpgradeService) upGraph(ctx context.Context, graph *topo.Graph[string,
}
aurUp = UpAUR(u.log, remote, aurdata, u.cfg.TimeUpdate, enableDowngrade)
}
if u.cfg.Devel {
u.log.OperationInfoln(gotext.Get("Checking development packages..."))
if u.cfg.Devel {
u.log.OperationInfoln(gotext.Get("Checking development packages..."))
develUp = UpDevel(ctx, u.log, remote, aurdata, u.vcsStore)
develUp = UpDevel(ctx, u.log, remote, aurdata, u.vcsStore)
u.vcsStore.CleanOrphans(remote)
u.vcsStore.CleanOrphans(remote)
}
}
}

View File

@ -76,7 +76,8 @@ func UpAUR(log *text.Logger, remote map[string]db.IPackage, aurdata map[string]*
}
if (timeUpdate && (int64(aurPkg.LastModified) > pkg.BuildDate().Unix())) ||
(db.VerCmp(pkg.Version(), aurPkg.Version) < 0) || enableDowngrade {
(db.VerCmp(pkg.Version(), aurPkg.Version) < 0) ||
(enableDowngrade && (db.VerCmp(pkg.Version(), aurPkg.Version) > 0)) {
if pkg.ShouldIgnore() {
printIgnoringPackage(log, pkg, aurPkg.Version)
} else {

View File

@ -21,9 +21,10 @@ func Test_upAUR(t *testing.T) {
t.Parallel()
type args struct {
remote map[string]alpm.IPackage
aurdata map[string]*aur.Pkg
timeUpdate bool
remote map[string]alpm.IPackage
aurdata map[string]*aur.Pkg
timeUpdate bool
enableDowngrade bool
}
tests := []struct {
name string
@ -57,6 +58,53 @@ func Test_upAUR(t *testing.T) {
},
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{{Name: "hello", Repository: "aur", LocalVersion: "2.0.0", RemoteVersion: "2.1.0"}}},
},
{
name: "Downgrade",
args: args{
remote: map[string]alpm.IPackage{
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0"},
},
aurdata: map[string]*aur.Pkg{"hello": {Version: "1.0.0", Name: "hello"}},
timeUpdate: false,
enableDowngrade: true,
},
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{{Name: "hello", Repository: "aur", LocalVersion: "2.0.0", RemoteVersion: "1.0.0"}}},
},
{
name: "Downgrade Disabled",
args: args{
remote: map[string]alpm.IPackage{
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0"},
},
aurdata: map[string]*aur.Pkg{"hello": {Version: "1.0.0", Name: "hello"}},
timeUpdate: false,
enableDowngrade: false,
},
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{}},
},
{
name: "Mixed Updates Downgrades",
args: args{
enableDowngrade: true,
remote: map[string]alpm.IPackage{
"up": &mock.Package{PName: "up", PVersion: "2.0.0"},
"same": &mock.Package{PName: "same", PVersion: "3.0.0"},
"down": &mock.Package{PName: "down", PVersion: "1.1.0"},
"ignored": &mock.Package{PName: "ignored", PVersion: "1.0.0", PShouldIgnore: true},
},
aurdata: map[string]*aur.Pkg{
"up": {Version: "2.1.0", Name: "up"},
"same": {Version: "3.0.0", Name: "same"},
"down": {Version: "1.0.0", Name: "down"},
"ignored": {Version: "2.0.0", Name: "ignored"},
},
timeUpdate: false,
},
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{
{Name: "up", Repository: "aur", LocalVersion: "2.0.0", RemoteVersion: "2.1.0"},
{Name: "down", Repository: "aur", LocalVersion: "1.1.0", RemoteVersion: "1.0.0"},
}},
},
{
name: "Time Update",
args: args{
@ -75,7 +123,7 @@ func Test_upAUR(t *testing.T) {
t.Parallel()
got := UpAUR(text.NewLogger(io.Discard, strings.NewReader(""), false, "test"),
tt.args.remote, tt.args.aurdata, tt.args.timeUpdate, false)
tt.args.remote, tt.args.aurdata, tt.args.timeUpdate, tt.args.enableDowngrade)
assert.EqualValues(t, tt.want, got)
})
}