Fix bug work with sqlite3

This commit is contained in:
Unknown 2014-03-30 16:01:50 -04:00
parent d0e6a4c25a
commit 2a0066420a
8 changed files with 31 additions and 12 deletions

View File

@ -26,6 +26,8 @@ type Access struct {
// AddAccess adds new access record. // AddAccess adds new access record.
func AddAccess(access *Access) error { func AddAccess(access *Access) error {
access.UserName = strings.ToLower(access.UserName)
access.RepoName = strings.ToLower(access.RepoName)
_, err := orm.Insert(access) _, err := orm.Insert(access)
return err return err
} }

View File

@ -12,6 +12,7 @@ import (
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq" _ "github.com/lib/pq"
"github.com/lunny/xorm" "github.com/lunny/xorm"
// _ "github.com/mattn/go-sqlite3"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
) )
@ -23,10 +24,15 @@ var (
DbCfg struct { DbCfg struct {
Type, Host, Name, User, Pwd, Path, SslMode string Type, Host, Name, User, Pwd, Path, SslMode string
} }
UseSQLite3 bool
) )
func LoadModelsConfig() { func LoadModelsConfig() {
DbCfg.Type = base.Cfg.MustValue("database", "DB_TYPE") DbCfg.Type = base.Cfg.MustValue("database", "DB_TYPE")
if DbCfg.Type == "sqlite3" {
UseSQLite3 = true
}
DbCfg.Host = base.Cfg.MustValue("database", "HOST") DbCfg.Host = base.Cfg.MustValue("database", "HOST")
DbCfg.Name = base.Cfg.MustValue("database", "NAME") DbCfg.Name = base.Cfg.MustValue("database", "NAME")
DbCfg.User = base.Cfg.MustValue("database", "USER") DbCfg.User = base.Cfg.MustValue("database", "USER")

View File

@ -157,7 +157,7 @@ func CreateRepository(user *User, repoName, desc, repoLang, license string, priv
} }
access := Access{ access := Access{
UserName: user.Name, UserName: user.LowerName,
RepoName: strings.ToLower(path.Join(user.Name, repo.Name)), RepoName: strings.ToLower(path.Join(user.Name, repo.Name)),
Mode: AU_WRITABLE, Mode: AU_WRITABLE,
} }

View File

@ -39,6 +39,7 @@ var (
ErrUserNotExist = errors.New("User does not exist") ErrUserNotExist = errors.New("User does not exist")
ErrEmailAlreadyUsed = errors.New("E-mail already used") ErrEmailAlreadyUsed = errors.New("E-mail already used")
ErrUserNameIllegal = errors.New("User name contains illegal characters") ErrUserNameIllegal = errors.New("User name contains illegal characters")
ErrKeyNotExist = errors.New("Public key does not exist")
) )
// User represents the object of individual and member of organization. // User represents the object of individual and member of organization.

View File

@ -212,9 +212,9 @@ func newMailService() {
if Cfg.MustBool("mailer", "ENABLED") { if Cfg.MustBool("mailer", "ENABLED") {
MailService = &Mailer{ MailService = &Mailer{
Name: Cfg.MustValue("mailer", "NAME", AppName), Name: Cfg.MustValue("mailer", "NAME", AppName),
Host: Cfg.MustValue("mailer", "HOST", "127.0.0.1:25"), Host: Cfg.MustValue("mailer", "HOST"),
User: Cfg.MustValue("mailer", "USER", "example@example.com"), User: Cfg.MustValue("mailer", "USER"),
Passwd: Cfg.MustValue("mailer", "PASSWD", "******"), Passwd: Cfg.MustValue("mailer", "PASSWD"),
} }
log.Info("Mail Service Enabled") log.Info("Mail Service Enabled")
} }

View File

@ -185,6 +185,7 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form) ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form)
return return
} }
log.Info("Admin account already exist")
} }
log.Info("First-time run install finished!") log.Info("First-time run install finished!")

View File

@ -74,29 +74,33 @@ func In(b string, sl map[string]int) bool {
func runServ(k *cli.Context) { func runServ(k *cli.Context) {
execDir, _ := base.ExecDir() execDir, _ := base.ExecDir()
newLogger(execDir) newLogger(execDir)
log.Trace("new serv request " + log.Mode + ":" + log.Config)
base.NewConfigContext() base.NewConfigContext()
models.LoadModelsConfig() models.LoadModelsConfig()
if models.UseSQLite3 {
os.Chdir(execDir)
}
models.SetEngine() models.SetEngine()
keys := strings.Split(os.Args[2], "-") keys := strings.Split(os.Args[2], "-")
if len(keys) != 2 { if len(keys) != 2 {
fmt.Println("auth file format error") println("auth file format error")
log.Error("auth file format error") log.Error("auth file format error")
return return
} }
keyId, err := strconv.ParseInt(keys[1], 10, 64) keyId, err := strconv.ParseInt(keys[1], 10, 64)
if err != nil { if err != nil {
fmt.Println("auth file format error") println("auth file format error")
log.Error("auth file format error", err) log.Error("auth file format error", err)
return return
} }
user, err := models.GetUserByKeyId(keyId) user, err := models.GetUserByKeyId(keyId)
if err != nil { if err != nil {
fmt.Println("You have no right to access") println("You have no right to access")
log.Error("SSH visit error", err) log.Error("SSH visit error: %v", err)
return return
} }
@ -133,13 +137,12 @@ func runServ(k *cli.Context) {
// access check // access check
switch { switch {
case isWrite: case isWrite:
has, err := models.HasAccess(user.Name, strings.ToLower(path.Join(repoUserName, repoName)), models.AU_WRITABLE) has, err := models.HasAccess(user.LowerName, path.Join(repoUserName, repoName), models.AU_WRITABLE)
if err != nil { if err != nil {
println("Inernel error:", err) println("Inernel error:", err)
log.Error(err.Error()) log.Error(err.Error())
return return
} } else if !has {
if !has {
println("You have no right to write this repository") println("You have no right to write this repository")
log.Error("User %s has no right to write repository %s", user.Name, repoPath) log.Error("User %s has no right to write repository %s", user.Name, repoPath)
return return

View File

@ -32,6 +32,12 @@ gogs serv provide access auth for repositories`,
func runUpdate(c *cli.Context) { func runUpdate(c *cli.Context) {
base.NewConfigContext() base.NewConfigContext()
models.LoadModelsConfig() models.LoadModelsConfig()
if models.UseSQLite3 {
execDir, _ := base.ExecDir()
os.Chdir(execDir)
}
models.SetEngine() models.SetEngine()
w, _ := os.Create("update.log") w, _ := os.Create("update.log")