]> source.dussan.org Git - gitea.git/commitdiff
Fix bug work with sqlite3
authorUnknown <joe2010xtmf@163.com>
Sun, 30 Mar 2014 20:01:50 +0000 (16:01 -0400)
committerUnknown <joe2010xtmf@163.com>
Sun, 30 Mar 2014 20:01:50 +0000 (16:01 -0400)
models/access.go
models/models.go
models/repo.go
models/user.go
modules/base/conf.go
routers/install.go
serve.go
update.go

index 84cad17a3fa30531552a710631478925e569d1c0..42fccae055cb2da00fba40c71cdbf018a5ba16e3 100644 (file)
@@ -26,6 +26,8 @@ type Access struct {
 
 // AddAccess adds new access record.
 func AddAccess(access *Access) error {
+       access.UserName = strings.ToLower(access.UserName)
+       access.RepoName = strings.ToLower(access.RepoName)
        _, err := orm.Insert(access)
        return err
 }
index be176b5d39f2464068925edea7bdd9614a5096d3..a626b98f6e6eb2ec38ebbacfc2f38c8b3917198f 100644 (file)
@@ -12,6 +12,7 @@ import (
        _ "github.com/go-sql-driver/mysql"
        _ "github.com/lib/pq"
        "github.com/lunny/xorm"
+       // _ "github.com/mattn/go-sqlite3"
 
        "github.com/gogits/gogs/modules/base"
 )
@@ -23,10 +24,15 @@ var (
        DbCfg struct {
                Type, Host, Name, User, Pwd, Path, SslMode string
        }
+
+       UseSQLite3 bool
 )
 
 func LoadModelsConfig() {
        DbCfg.Type = base.Cfg.MustValue("database", "DB_TYPE")
+       if DbCfg.Type == "sqlite3" {
+               UseSQLite3 = true
+       }
        DbCfg.Host = base.Cfg.MustValue("database", "HOST")
        DbCfg.Name = base.Cfg.MustValue("database", "NAME")
        DbCfg.User = base.Cfg.MustValue("database", "USER")
index 5ca98dec0ca91cce72d68368cde829d8f66b7381..0c808f18456e85d077dc5cd58a6436843101d4b4 100644 (file)
@@ -157,7 +157,7 @@ func CreateRepository(user *User, repoName, desc, repoLang, license string, priv
        }
 
        access := Access{
-               UserName: user.Name,
+               UserName: user.LowerName,
                RepoName: strings.ToLower(path.Join(user.Name, repo.Name)),
                Mode:     AU_WRITABLE,
        }
index a392fa76baaa92621f049d61e8e262f78e5e9b9f..4908552f291bd642e91b4970b407d1e679bc00d0 100644 (file)
@@ -39,6 +39,7 @@ var (
        ErrUserNotExist     = errors.New("User does not exist")
        ErrEmailAlreadyUsed = errors.New("E-mail already used")
        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.
index 0233d0033590bcd0ad252785a455949ab990677c..3ebc4ede18cac9f2ea87e8b45688884944c14aaa 100644 (file)
@@ -212,9 +212,9 @@ func newMailService() {
        if Cfg.MustBool("mailer", "ENABLED") {
                MailService = &Mailer{
                        Name:   Cfg.MustValue("mailer", "NAME", AppName),
-                       Host:   Cfg.MustValue("mailer", "HOST", "127.0.0.1:25"),
-                       User:   Cfg.MustValue("mailer", "USER", "example@example.com"),
-                       Passwd: Cfg.MustValue("mailer", "PASSWD", "******"),
+                       Host:   Cfg.MustValue("mailer", "HOST"),
+                       User:   Cfg.MustValue("mailer", "USER"),
+                       Passwd: Cfg.MustValue("mailer", "PASSWD"),
                }
                log.Info("Mail Service Enabled")
        }
index 2c993c559e6c61b39254462fb9eb79cc0c309f75..e30c3cfd23ed40ef1e5fe1ffb770f4427622bf25 100644 (file)
@@ -185,6 +185,7 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
                        ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form)
                        return
                }
+               log.Info("Admin account already exist")
        }
 
        log.Info("First-time run install finished!")
index dcbddfe4a9dd0f4c1c53bba73e8dbe0614515e03..96cd7e73def0b91672fd9b23bc3f19ebc742e00a 100644 (file)
--- a/serve.go
+++ b/serve.go
@@ -74,29 +74,33 @@ func In(b string, sl map[string]int) bool {
 func runServ(k *cli.Context) {
        execDir, _ := base.ExecDir()
        newLogger(execDir)
-       log.Trace("new serv request " + log.Mode + ":" + log.Config)
 
        base.NewConfigContext()
        models.LoadModelsConfig()
+
+       if models.UseSQLite3 {
+               os.Chdir(execDir)
+       }
+
        models.SetEngine()
 
        keys := strings.Split(os.Args[2], "-")
        if len(keys) != 2 {
-               fmt.Println("auth file format error")
+               println("auth file format error")
                log.Error("auth file format error")
                return
        }
 
        keyId, err := strconv.ParseInt(keys[1], 10, 64)
        if err != nil {
-               fmt.Println("auth file format error")
+               println("auth file format error")
                log.Error("auth file format error", err)
                return
        }
        user, err := models.GetUserByKeyId(keyId)
        if err != nil {
-               fmt.Println("You have no right to access")
-               log.Error("SSH visit error", err)
+               println("You have no right to access")
+               log.Error("SSH visit error: %v", err)
                return
        }
 
@@ -133,13 +137,12 @@ func runServ(k *cli.Context) {
        // access check
        switch {
        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 {
                        println("Inernel error:", err)
                        log.Error(err.Error())
                        return
-               }
-               if !has {
+               } else if !has {
                        println("You have no right to write this repository")
                        log.Error("User %s has no right to write repository %s", user.Name, repoPath)
                        return
index 246c5d8f9d069defad1ad4d157609e8981bf1525..e36dc223297f16f9d930b48cd64041f5bcb24d4e 100644 (file)
--- a/update.go
+++ b/update.go
@@ -32,6 +32,12 @@ gogs serv provide access auth for repositories`,
 func runUpdate(c *cli.Context) {
        base.NewConfigContext()
        models.LoadModelsConfig()
+
+       if models.UseSQLite3 {
+               execDir, _ := base.ExecDir()
+               os.Chdir(execDir)
+       }
+
        models.SetEngine()
 
        w, _ := os.Create("update.log")