From 9f91dee53fc602a939abf1219ec6ddb128c2067c Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 30 Mar 2014 11:09:59 -0400 Subject: [PATCH] Bug fix #45 --- models/models.go | 6 +++--- modules/base/conf.go | 4 ++-- routers/install.go | 28 +++++++++++++--------------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/models/models.go b/models/models.go index 06533e45f..be176b5d3 100644 --- a/models/models.go +++ b/models/models.go @@ -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) } diff --git a/modules/base/conf.go b/modules/base/conf.go index f696d083f..0233d0033 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -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) } } diff --git a/routers/install.go b/routers/install.go index 20e424195..6f29badcf 100644 --- a/routers/install.go +++ b/routers/install.go @@ -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") }