]> source.dussan.org Git - gitea.git/commitdiff
Fix SSH key bug in windows
authorUnknown <joe2010xtmf@163.com>
Sat, 22 Mar 2014 18:27:03 +0000 (14:27 -0400)
committerUnknown <joe2010xtmf@163.com>
Sat, 22 Mar 2014 18:27:03 +0000 (14:27 -0400)
models/publickey.go
models/repo.go
models/user.go
modules/middleware/auth.go
modules/middleware/context.go
routers/repo/issue.go

index c69bca681d664e7ff775ad73baccfdcac6019d83..9e7cc6f740ca3daa1851ca52b5176acc0fd30f7b 100644 (file)
@@ -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)
index fb115de59099de4793dc46f678f685a1e27eb907..317f936ece2ebb431a6cee6f885659f1ccd5a542 100644 (file)
@@ -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
 }
 
index d6dc04149073b8734b982b20622dec7e7bae1620..88c29ae43e71681f01a28ff3256e90479b0ce178 100644 (file)
@@ -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
 }
 
index b557188ee92bd8298d4057edaa26dbd950301e2c..3224b3df91a261f36fcabbf95a234b9c32ed3c69 100644 (file)
@@ -49,6 +49,7 @@ func Toggle(options *ToggleOptions) martini.Handler {
                                ctx.Error(403)
                                return
                        }
+                       ctx.Data["PageIsAdmin"] = true
                }
        }
 }
index b28953fc0ede9c7f18a19b070ef1531ad956a529..5727b4f094a60f605391c7d8be6bd360069299cc 100644 (file)
@@ -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
index c6af8ca0bc45aa8e5816b67d7ccb4fe9af865ddf..eee55c6fdaea957077f7a0b5dedb406b0517fb04 100644 (file)
@@ -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 {
+
+       // }
+}