Skip to content

Commit b3cfd9f

Browse files
committed
Fix SSH key bug in windows
1 parent e385efc commit b3cfd9f

File tree

6 files changed

+40
-24
lines changed

6 files changed

+40
-24
lines changed

models/publickey.go

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"time"
2020

2121
"github.com/Unknwon/com"
22+
23+
"github.com/gogits/gogs/modules/log"
2224
)
2325

2426
const (
@@ -99,8 +101,8 @@ func AddPublicKey(key *PublicKey) (err error) {
99101
}
100102

101103
// Calculate fingerprint.
102-
tmpPath := filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()),
103-
"id_rsa.pub")
104+
tmpPath := strings.Replace(filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()),
105+
"id_rsa.pub"), "\\", "/", -1)
104106
os.MkdirAll(path.Dir(tmpPath), os.ModePerm)
105107
if err = ioutil.WriteFile(tmpPath, []byte(key.Content), os.ModePerm); err != nil {
106108
return err
@@ -127,25 +129,11 @@ func AddPublicKey(key *PublicKey) (err error) {
127129
return nil
128130
}
129131

130-
// DeletePublicKey deletes SSH key information both in database and authorized_keys file.
131-
func DeletePublicKey(key *PublicKey) (err error) {
132-
// Delete SSH key in database.
133-
has, err := orm.Id(key.Id).Get(key)
134-
if err != nil {
135-
return err
136-
} else if !has {
137-
return errors.New("Public key does not exist")
138-
}
139-
if _, err = orm.Delete(key); err != nil {
140-
return err
141-
}
142-
132+
func rewriteAuthorizedKeys(key *PublicKey, p, tmpP string) error {
143133
// Delete SSH key in SSH key file.
144134
sshOpLocker.Lock()
145135
defer sshOpLocker.Unlock()
146136

147-
p := filepath.Join(sshPath, "authorized_keys")
148-
tmpP := filepath.Join(sshPath, "authorized_keys.tmp")
149137
fr, err := os.Open(p)
150138
if err != nil {
151139
return err
@@ -188,8 +176,29 @@ func DeletePublicKey(key *PublicKey) (err error) {
188176
break
189177
}
190178
}
179+
return nil
180+
}
191181

192-
if err = os.Remove(p); err != nil {
182+
// DeletePublicKey deletes SSH key information both in database and authorized_keys file.
183+
func DeletePublicKey(key *PublicKey) (err error) {
184+
// Delete SSH key in database.
185+
has, err := orm.Id(key.Id).Get(key)
186+
if err != nil {
187+
return err
188+
} else if !has {
189+
return errors.New("Public key does not exist")
190+
}
191+
if _, err = orm.Delete(key); err != nil {
192+
return err
193+
}
194+
195+
p := filepath.Join(sshPath, "authorized_keys")
196+
tmpP := filepath.Join(sshPath, "authorized_keys.tmp")
197+
log.Trace("ssh.DeletePublicKey(authorized_keys): %s", p)
198+
199+
if err = rewriteAuthorizedKeys(key, p, tmpP); err != nil {
200+
return err
201+
} else if err = os.Remove(p); err != nil {
193202
return err
194203
}
195204
return os.Rename(tmpP, p)

models/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func RepoPath(userName, repoName string) string {
372372
}
373373

374374
func UpdateRepository(repo *Repository) error {
375-
_, err := orm.Id(repo.Id).UseBool().Update(repo)
375+
_, err := orm.Id(repo.Id).UseBool().Cols("description", "website").Update(repo)
376376
return err
377377
}
378378

models/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func VerifyUserActiveCode(code string) (user *User) {
201201

202202
// UpdateUser updates user's information.
203203
func UpdateUser(user *User) (err error) {
204-
_, err = orm.Id(user.Id).UseBool().Update(user)
204+
_, err = orm.Id(user.Id).UseBool().Cols("website", "location").Update(user)
205205
return err
206206
}
207207

modules/middleware/auth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func Toggle(options *ToggleOptions) martini.Handler {
4949
ctx.Error(403)
5050
return
5151
}
52+
ctx.Data["PageIsAdmin"] = true
5253
}
5354
}
5455
}

modules/middleware/context.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,6 @@ func InitContext() martini.Handler {
216216
ctx.Data["SignedUserId"] = user.Id
217217
ctx.Data["SignedUserName"] = user.LowerName
218218
ctx.Data["IsAdmin"] = ctx.User.IsAdmin
219-
220-
if ctx.User.IsAdmin {
221-
ctx.Data["PageIsAdmin"] = true
222-
}
223219
}
224220

225221
// get or create csrf token

routers/repo/issue.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,13 @@ func Issues(ctx *middleware.Context, params martini.Params) {
2828

2929
ctx.HTML(200, "repo/issues")
3030
}
31+
32+
func CreateIssue(ctx *middleware.Context, params martini.Params) {
33+
if !ctx.Repo.IsOwner {
34+
ctx.Error(404)
35+
return
36+
}
37+
// else if err = models.CreateIssue(userId, repoId, milestoneId, assigneeId, name, labels, mentions, content, isPull); err != nil {
38+
39+
// }
40+
}

0 commit comments

Comments
 (0)