forked from gitea/gitea
Bug fix #45
This commit is contained in:
parent
a6e12aaef6
commit
9f91dee53f
|
@ -43,9 +43,9 @@ func NewTestEngine(x *xorm.Engine) (err error) {
|
|||
case "postgres":
|
||||
x, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s",
|
||||
DbCfg.User, DbCfg.Pwd, DbCfg.Name, DbCfg.SslMode))
|
||||
case "sqlite3":
|
||||
os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm)
|
||||
x, err = xorm.NewEngine("sqlite3", DbCfg.Path)
|
||||
// case "sqlite3":
|
||||
// os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm)
|
||||
// x, err = xorm.NewEngine("sqlite3", DbCfg.Path)
|
||||
default:
|
||||
return fmt.Errorf("Unknown database type: %s\n", DbCfg.Type)
|
||||
}
|
||||
|
|
|
@ -253,7 +253,7 @@ func NewConfigContext() {
|
|||
cfgPath := filepath.Join(workDir, "conf/app.ini")
|
||||
Cfg, err = goconfig.LoadConfigFile(cfgPath)
|
||||
if err != nil {
|
||||
fmt.Printf("Cannot load config file '%s'\n", cfgPath)
|
||||
fmt.Printf("Cannot load config file(%s): %v\n", cfgPath, err)
|
||||
os.Exit(2)
|
||||
}
|
||||
Cfg.BlockMode = false
|
||||
|
@ -261,7 +261,7 @@ func NewConfigContext() {
|
|||
cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
|
||||
if com.IsFile(cfgPath) {
|
||||
if err = Cfg.AppendFiles(cfgPath); err != nil {
|
||||
fmt.Printf("Cannot load config file '%s'\n", cfgPath)
|
||||
fmt.Printf("Cannot load config file(%s): %v\n", cfgPath, err)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
"github.com/Unknwon/goconfig"
|
||||
"github.com/codegangsta/martini"
|
||||
// "github.com/lunny/xorm"
|
||||
"github.com/lunny/xorm"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/auth"
|
||||
|
@ -113,12 +113,10 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
|
|||
models.DbCfg.SslMode = form.SslMode
|
||||
models.DbCfg.Path = form.DatabasePath
|
||||
|
||||
// ctx.RenderWithErr("Database setting is not correct: ", "install", &form)
|
||||
// return
|
||||
log.Trace("00000000000000000000000000000000000000000000")
|
||||
// Set test engine.
|
||||
var x *xorm.Engine
|
||||
if err := models.NewTestEngine(x); err != nil {
|
||||
if strings.Contains(err.Error(), `unknown driver "sqlite3"`) {
|
||||
if strings.Contains(err.Error(), `Unknown database type: sqlite3`) {
|
||||
ctx.RenderWithErr("Your release version does not support SQLite3, please download the official binary version "+
|
||||
"from https://github.com/gogits/gogs/wiki/Install-from-binary, NOT the gobuild version.", "install", &form)
|
||||
} else {
|
||||
|
@ -133,15 +131,6 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
|
|||
return
|
||||
}
|
||||
|
||||
// Create admin account.
|
||||
if _, err := models.RegisterUser(&models.User{Name: form.AdminName, Email: form.AdminEmail, Passwd: form.AdminPasswd,
|
||||
IsAdmin: true, IsActive: true}); err != nil {
|
||||
if err != models.ErrUserAlreadyExist {
|
||||
ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Save settings.
|
||||
base.Cfg.SetValue("database", "DB_TYPE", models.DbCfg.Type)
|
||||
base.Cfg.SetValue("database", "HOST", models.DbCfg.Host)
|
||||
|
@ -168,13 +157,22 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
|
|||
|
||||
base.Cfg.SetValue("security", "INSTALL_LOCK", "true")
|
||||
|
||||
if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app1.ini"); err != nil {
|
||||
if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app.ini"); err != nil {
|
||||
ctx.RenderWithErr("Fail to save configuration: "+err.Error(), "install", &form)
|
||||
return
|
||||
}
|
||||
|
||||
GlobalInit()
|
||||
|
||||
// Create admin account.
|
||||
if _, err := models.RegisterUser(&models.User{Name: form.AdminName, Email: form.AdminEmail, Passwd: form.AdminPasswd,
|
||||
IsAdmin: true, IsActive: true}); err != nil {
|
||||
if err != models.ErrUserAlreadyExist {
|
||||
ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
log.Info("First-time run install finished!")
|
||||
ctx.Redirect("/user/login")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue