mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-27 07:56:13 +00:00
Fixing bug
This commit is contained in:
parent
03cc39ea12
commit
a6e12aaef6
@ -18,6 +18,7 @@ import (
|
||||
|
||||
var (
|
||||
orm *xorm.Engine
|
||||
HasEngine bool
|
||||
|
||||
DbCfg struct {
|
||||
Type, Host, Name, User, Pwd, Path, SslMode string
|
||||
@ -34,6 +35,28 @@ func LoadModelsConfig() {
|
||||
DbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db")
|
||||
}
|
||||
|
||||
func NewTestEngine(x *xorm.Engine) (err error) {
|
||||
switch DbCfg.Type {
|
||||
case "mysql":
|
||||
x, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8",
|
||||
DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name))
|
||||
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)
|
||||
default:
|
||||
return fmt.Errorf("Unknown database type: %s\n", DbCfg.Type)
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("models.init(fail to conntect database): %v\n", err)
|
||||
}
|
||||
|
||||
return x.Sync(new(User), new(PublicKey), new(Repository), new(Watch),
|
||||
new(Action), new(Access), new(Issue), new(Comment))
|
||||
}
|
||||
|
||||
func SetEngine() (err error) {
|
||||
switch DbCfg.Type {
|
||||
case "mysql":
|
||||
|
@ -21,6 +21,10 @@ import (
|
||||
|
||||
// SignedInId returns the id of signed in user.
|
||||
func SignedInId(session session.SessionStore) int64 {
|
||||
if !models.HasEngine {
|
||||
return 0
|
||||
}
|
||||
|
||||
userId := session.Get("userId")
|
||||
if userId == nil {
|
||||
return 0
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/Unknwon/goconfig"
|
||||
"github.com/codegangsta/martini"
|
||||
// "github.com/lunny/xorm"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/auth"
|
||||
@ -38,10 +39,15 @@ func GlobalInit() {
|
||||
models.LoadModelsConfig()
|
||||
models.LoadRepoConfig()
|
||||
models.NewRepoContext()
|
||||
if err := models.NewEngine(); err != nil && base.InstallLock {
|
||||
|
||||
if base.InstallLock {
|
||||
if err := models.NewEngine(); err != nil {
|
||||
log.Error("%v", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
models.HasEngine = true
|
||||
}
|
||||
base.NewServices()
|
||||
checkRunMode()
|
||||
}
|
||||
@ -107,7 +113,11 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
|
||||
models.DbCfg.SslMode = form.SslMode
|
||||
models.DbCfg.Path = form.DatabasePath
|
||||
|
||||
if err := models.NewEngine(); err != nil {
|
||||
// ctx.RenderWithErr("Database setting is not correct: ", "install", &form)
|
||||
// return
|
||||
log.Trace("00000000000000000000000000000000000000000000")
|
||||
var x *xorm.Engine
|
||||
if err := models.NewTestEngine(x); err != nil {
|
||||
if strings.Contains(err.Error(), `unknown driver "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)
|
||||
@ -158,7 +168,7 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
|
||||
|
||||
base.Cfg.SetValue("security", "INSTALL_LOCK", "true")
|
||||
|
||||
if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app.ini"); err != nil {
|
||||
if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app1.ini"); err != nil {
|
||||
ctx.RenderWithErr("Fail to save configuration: "+err.Error(), "install", &form)
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user