From a3e1383cac3dfa2a71b04b47a295e9836fcb0d50 Mon Sep 17 00:00:00 2001
From: Unknown <joe2010xtmf@163.com>
Date: Tue, 10 Jun 2014 19:11:53 -0400
Subject: Add gogs fix location command

---
 models/models.go    |  5 +++--
 models/publickey.go | 14 +++++++-------
 models/repo.go      |  6 +++++-
 3 files changed, 15 insertions(+), 10 deletions(-)

(limited to 'models')

diff --git a/models/models.go b/models/models.go
index dca77e00e1..a59c051712 100644
--- a/models/models.go
+++ b/models/models.go
@@ -46,7 +46,9 @@ func LoadModelsConfig() {
 	DbCfg.Host = setting.Cfg.MustValue("database", "HOST")
 	DbCfg.Name = setting.Cfg.MustValue("database", "NAME")
 	DbCfg.User = setting.Cfg.MustValue("database", "USER")
-	DbCfg.Pwd = setting.Cfg.MustValue("database", "PASSWD")
+	if len(DbCfg.Pwd) == 0 {
+		DbCfg.Pwd = setting.Cfg.MustValue("database", "PASSWD")
+	}
 	DbCfg.SslMode = setting.Cfg.MustValue("database", "SSL_MODE")
 	DbCfg.Path = setting.Cfg.MustValue("database", "PATH", "data/gogs.db")
 }
@@ -67,7 +69,6 @@ func NewTestEngine(x *xorm.Engine) (err error) {
 		}
 		cnnstr := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s",
 			DbCfg.User, DbCfg.Pwd, host, port, DbCfg.Name, DbCfg.SslMode)
-		//fmt.Println(cnnstr)
 		x, err = xorm.NewEngine("postgres", cnnstr)
 	case "sqlite3":
 		if !EnableSQLite3 {
diff --git a/models/publickey.go b/models/publickey.go
index 556db96491..76dc0cc740 100644
--- a/models/publickey.go
+++ b/models/publickey.go
@@ -37,7 +37,7 @@ var (
 var sshOpLocker = sync.Mutex{}
 
 var (
-	sshPath string // SSH directory.
+	SshPath string // SSH directory.
 	appPath string // Execution(binary) path.
 )
 
@@ -67,9 +67,9 @@ func init() {
 	}
 
 	// Determine and create .ssh path.
-	sshPath = filepath.Join(homeDir(), ".ssh")
-	if err = os.MkdirAll(sshPath, os.ModePerm); err != nil {
-		qlog.Fatalf("publickey.init(fail to create sshPath(%s)): %v\n", sshPath, err)
+	SshPath = filepath.Join(homeDir(), ".ssh")
+	if err = os.MkdirAll(SshPath, os.ModePerm); err != nil {
+		qlog.Fatalf("publickey.init(fail to create SshPath(%s)): %v\n", SshPath, err)
 	}
 }
 
@@ -94,7 +94,7 @@ func saveAuthorizedKeyFile(key *PublicKey) error {
 	sshOpLocker.Lock()
 	defer sshOpLocker.Unlock()
 
-	fpath := filepath.Join(sshPath, "authorized_keys")
+	fpath := filepath.Join(SshPath, "authorized_keys")
 	f, err := os.OpenFile(fpath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
 	if err != nil {
 		return err
@@ -216,8 +216,8 @@ func DeletePublicKey(key *PublicKey) error {
 		return err
 	}
 
-	fpath := filepath.Join(sshPath, "authorized_keys")
-	tmpPath := filepath.Join(sshPath, "authorized_keys.tmp")
+	fpath := filepath.Join(SshPath, "authorized_keys")
+	tmpPath := filepath.Join(SshPath, "authorized_keys.tmp")
 	log.Trace("publickey.DeletePublicKey(authorized_keys): %s", fpath)
 
 	if err = rewriteAuthorizedKeys(key, fpath, tmpPath); err != nil {
diff --git a/models/repo.go b/models/repo.go
index deb25b2a9a..3eca78c4b9 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -28,6 +28,10 @@ import (
 	"github.com/gogits/gogs/modules/setting"
 )
 
+const (
+	TPL_UPDATE_HOOK = "#!/usr/bin/env %s\n%s update $1 $2 $3\n"
+)
+
 var (
 	ErrRepoAlreadyExist  = errors.New("Repository already exist")
 	ErrRepoNotExist      = errors.New("Repository does not exist")
@@ -450,7 +454,7 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep
 	rp := strings.NewReplacer("\\", "/", " ", "\\ ")
 	// hook/post-update
 	if err := createHookUpdate(filepath.Join(repoPath, "hooks", "update"),
-		fmt.Sprintf("#!/usr/bin/env %s\n%s update $1 $2 $3\n", setting.ScriptType,
+		fmt.Sprintf(TPL_UPDATE_HOOK, setting.ScriptType,
 			rp.Replace(appPath))); err != nil {
 		return err
 	}
-- 
cgit v1.2.3