From b3cfd9fe0c293ba9d84d38ec140db2c01b1e3109 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 22 Mar 2014 14:27:03 -0400 Subject: [PATCH] Fix SSH key bug in windows --- models/publickey.go | 45 +++++++++++++++++++++-------------- models/repo.go | 2 +- models/user.go | 2 +- modules/middleware/auth.go | 1 + modules/middleware/context.go | 4 ---- routers/repo/issue.go | 10 ++++++++ 6 files changed, 40 insertions(+), 24 deletions(-) diff --git a/models/publickey.go b/models/publickey.go index c69bca681d..9e7cc6f740 100644 --- a/models/publickey.go +++ b/models/publickey.go @@ -19,6 +19,8 @@ import ( "time" "github.com/Unknwon/com" + + "github.com/gogits/gogs/modules/log" ) const ( @@ -99,8 +101,8 @@ func AddPublicKey(key *PublicKey) (err error) { } // Calculate fingerprint. - tmpPath := filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()), - "id_rsa.pub") + tmpPath := strings.Replace(filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()), + "id_rsa.pub"), "\\", "/", -1) os.MkdirAll(path.Dir(tmpPath), os.ModePerm) if err = ioutil.WriteFile(tmpPath, []byte(key.Content), os.ModePerm); err != nil { return err @@ -127,25 +129,11 @@ func AddPublicKey(key *PublicKey) (err error) { return nil } -// DeletePublicKey deletes SSH key information both in database and authorized_keys file. -func DeletePublicKey(key *PublicKey) (err error) { - // Delete SSH key in database. - has, err := orm.Id(key.Id).Get(key) - if err != nil { - return err - } else if !has { - return errors.New("Public key does not exist") - } - if _, err = orm.Delete(key); err != nil { - return err - } - +func rewriteAuthorizedKeys(key *PublicKey, p, tmpP string) error { // Delete SSH key in SSH key file. sshOpLocker.Lock() defer sshOpLocker.Unlock() - p := filepath.Join(sshPath, "authorized_keys") - tmpP := filepath.Join(sshPath, "authorized_keys.tmp") fr, err := os.Open(p) if err != nil { return err @@ -188,8 +176,29 @@ func DeletePublicKey(key *PublicKey) (err error) { break } } + return nil +} - if err = os.Remove(p); err != nil { +// DeletePublicKey deletes SSH key information both in database and authorized_keys file. +func DeletePublicKey(key *PublicKey) (err error) { + // Delete SSH key in database. + has, err := orm.Id(key.Id).Get(key) + if err != nil { + return err + } else if !has { + return errors.New("Public key does not exist") + } + if _, err = orm.Delete(key); err != nil { + return err + } + + p := filepath.Join(sshPath, "authorized_keys") + tmpP := filepath.Join(sshPath, "authorized_keys.tmp") + log.Trace("ssh.DeletePublicKey(authorized_keys): %s", p) + + if err = rewriteAuthorizedKeys(key, p, tmpP); err != nil { + return err + } else if err = os.Remove(p); err != nil { return err } return os.Rename(tmpP, p) diff --git a/models/repo.go b/models/repo.go index fb115de590..317f936ece 100644 --- a/models/repo.go +++ b/models/repo.go @@ -372,7 +372,7 @@ func RepoPath(userName, repoName string) string { } func UpdateRepository(repo *Repository) error { - _, err := orm.Id(repo.Id).UseBool().Update(repo) + _, err := orm.Id(repo.Id).UseBool().Cols("description", "website").Update(repo) return err } diff --git a/models/user.go b/models/user.go index d6dc041490..88c29ae43e 100644 --- a/models/user.go +++ b/models/user.go @@ -201,7 +201,7 @@ func VerifyUserActiveCode(code string) (user *User) { // UpdateUser updates user's information. func UpdateUser(user *User) (err error) { - _, err = orm.Id(user.Id).UseBool().Update(user) + _, err = orm.Id(user.Id).UseBool().Cols("website", "location").Update(user) return err } diff --git a/modules/middleware/auth.go b/modules/middleware/auth.go index b557188ee9..3224b3df91 100644 --- a/modules/middleware/auth.go +++ b/modules/middleware/auth.go @@ -49,6 +49,7 @@ func Toggle(options *ToggleOptions) martini.Handler { ctx.Error(403) return } + ctx.Data["PageIsAdmin"] = true } } } diff --git a/modules/middleware/context.go b/modules/middleware/context.go index b28953fc0e..5727b4f094 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -216,10 +216,6 @@ func InitContext() martini.Handler { ctx.Data["SignedUserId"] = user.Id ctx.Data["SignedUserName"] = user.LowerName ctx.Data["IsAdmin"] = ctx.User.IsAdmin - - if ctx.User.IsAdmin { - ctx.Data["PageIsAdmin"] = true - } } // get or create csrf token diff --git a/routers/repo/issue.go b/routers/repo/issue.go index c6af8ca0bc..eee55c6fda 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -28,3 +28,13 @@ func Issues(ctx *middleware.Context, params martini.Params) { ctx.HTML(200, "repo/issues") } + +func CreateIssue(ctx *middleware.Context, params martini.Params) { + if !ctx.Repo.IsOwner { + ctx.Error(404) + return + } + // else if err = models.CreateIssue(userId, repoId, milestoneId, assigneeId, name, labels, mentions, content, isPull); err != nil { + + // } +}