Skip to content

Commit b49a195

Browse files
authored
models: fix xorm variable clobber (#12231)
NewTestEngine() takes a *xorm.Engine as its argument, and then immediately overwrites it. This fixes the model package to not take an unneeded variable, and changes the routers package to not create a nil *xorm.Engine that is immediately discarded by model.
1 parent 48ad76c commit b49a195

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

models/models.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func getEngine() (*xorm.Engine, error) {
151151
}
152152

153153
// NewTestEngine sets a new test xorm.Engine
154-
func NewTestEngine(x *xorm.Engine) (err error) {
154+
func NewTestEngine() (err error) {
155155
x, err = getEngine()
156156
if err != nil {
157157
return fmt.Errorf("Connect to database: %v", err)

routers/install.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/unknwon/com"
2525
"gopkg.in/ini.v1"
26-
"xorm.io/xorm"
2726
)
2827

2928
const (
@@ -161,8 +160,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
161160
}
162161

163162
// Set test engine.
164-
var x *xorm.Engine
165-
if err = models.NewTestEngine(x); err != nil {
163+
if err = models.NewTestEngine(); err != nil {
166164
if strings.Contains(err.Error(), `Unknown database type: sqlite3`) {
167165
ctx.Data["Err_DbType"] = true
168166
ctx.RenderWithErr(ctx.Tr("install.sqlite3_not_available", "https://docs.gitea.io/en-us/install-from-binary/"), tplInstall, &form)

0 commit comments

Comments
 (0)