#2558 delete local wiki copy when rename repo and user
This commit is contained in:
parent
4e96a4a62b
commit
f8182ac521
6 changed files with 40 additions and 25 deletions
|
@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
|
|||
|
||||
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
|
||||
|
||||
##### Current version: 0.8.30
|
||||
##### Current version: 0.8.31
|
||||
|
||||
| Web | UI | Preview |
|
||||
|:-------------:|:-------:|:-------:|
|
||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const APP_VER = "0.8.30.0204"
|
||||
const APP_VER = "0.8.31.0205"
|
||||
|
||||
func init() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
|
|
@ -5,12 +5,15 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Unknwon/com"
|
||||
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
)
|
||||
|
||||
type NoticeType int
|
||||
|
@ -47,6 +50,18 @@ func CreateRepositoryNotice(desc string) error {
|
|||
return CreateNotice(NOTICE_REPOSITORY, desc)
|
||||
}
|
||||
|
||||
// RemoveAllWithNotice removes all directories in given path and
|
||||
// creates a system notice when error occurs.
|
||||
func RemoveAllWithNotice(title, path string) {
|
||||
if err := os.RemoveAll(path); err != nil {
|
||||
desc := fmt.Sprintf("%s [%s]: %v", title, path, err)
|
||||
log.Warn(desc)
|
||||
if err = CreateRepositoryNotice(desc); err != nil {
|
||||
log.Error(4, "CreateRepositoryNotice: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CountNotices returns number of notices.
|
||||
func CountNotices() int64 {
|
||||
count, _ := x.Count(new(Notice))
|
||||
|
|
|
@ -1123,16 +1123,22 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error)
|
|||
return ErrRepoAlreadyExist{u.Name, newRepoName}
|
||||
}
|
||||
|
||||
repo, err := GetRepositoryByName(u.Id, oldRepoName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepositoryByName: %v", err)
|
||||
}
|
||||
|
||||
// Change repository directory name.
|
||||
if err = os.Rename(RepoPath(u.Name, oldRepoName), RepoPath(u.Name, newRepoName)); err != nil {
|
||||
if err = os.Rename(repo.RepoPath(), RepoPath(u.Name, newRepoName)); err != nil {
|
||||
return fmt.Errorf("rename repository directory: %v", err)
|
||||
}
|
||||
|
||||
wikiPath := WikiPath(u.Name, oldRepoName)
|
||||
wikiPath := repo.WikiPath()
|
||||
if com.IsExist(wikiPath) {
|
||||
if err = os.Rename(wikiPath, WikiPath(u.Name, newRepoName)); err != nil {
|
||||
return fmt.Errorf("rename repository wiki: %v", err)
|
||||
}
|
||||
RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -1295,30 +1301,16 @@ func DeleteRepository(uid, repoID int64) error {
|
|||
|
||||
// Remove repository files.
|
||||
repoPath := repo.repoPath(sess)
|
||||
if err = os.RemoveAll(repoPath); err != nil {
|
||||
desc := fmt.Sprintf("delete repository files [%s]: %v", repoPath, err)
|
||||
log.Warn(desc)
|
||||
if err = CreateRepositoryNotice(desc); err != nil {
|
||||
log.Error(4, "CreateRepositoryNotice: %v", err)
|
||||
}
|
||||
}
|
||||
RemoveAllWithNotice("Delete repository files", repoPath)
|
||||
|
||||
wikiPaths := []string{repo.WikiPath(), repo.LocalWikiPath()}
|
||||
for _, wikiPath := range wikiPaths {
|
||||
if err = os.RemoveAll(wikiPath); err != nil {
|
||||
desc := fmt.Sprintf("delete repository wiki [%s]: %v", wikiPath, err)
|
||||
log.Warn(desc)
|
||||
if err = CreateRepositoryNotice(desc); err != nil {
|
||||
log.Error(4, "CreateRepositoryNotice: %v", err)
|
||||
}
|
||||
}
|
||||
RemoveAllWithNotice("Delete repository wiki", wikiPath)
|
||||
}
|
||||
|
||||
// Remove attachment files.
|
||||
for i := range attachmentPaths {
|
||||
if err = os.Remove(attachmentPaths[i]); err != nil {
|
||||
log.Warn("delete attachment: %v", err)
|
||||
}
|
||||
RemoveAllWithNotice("Delete attachment", attachmentPaths[i])
|
||||
}
|
||||
|
||||
if err = sess.Commit(); err != nil {
|
||||
|
@ -1333,7 +1325,7 @@ func DeleteRepository(uid, repoID int64) error {
|
|||
}
|
||||
for i := range forkRepos {
|
||||
if err = DeleteRepository(forkRepos[i].OwnerID, forkRepos[i].ID); err != nil {
|
||||
log.Error(4, "updateRepository[%d]: %v", forkRepos[i].ID, err)
|
||||
log.Error(4, "DeleteRepository [%d]: %v", forkRepos[i].ID, err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -598,11 +598,19 @@ func ChangeUserName(u *User, newUserName string) (err error) {
|
|||
return ErrUserAlreadyExist{newUserName}
|
||||
}
|
||||
|
||||
err = ChangeUsernameInPullRequests(u.Name, newUserName)
|
||||
if err != nil {
|
||||
if err = ChangeUsernameInPullRequests(u.Name, newUserName); err != nil {
|
||||
return fmt.Errorf("ChangeUsernameInPullRequests: %v", err)
|
||||
}
|
||||
|
||||
// Delete all local copies of repository wiki that user owns.
|
||||
if err = x.Where("owner_id=?", u.Id).Iterate(new(Repository), func(idx int, bean interface{}) error {
|
||||
repo := bean.(*Repository)
|
||||
RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
|
||||
return nil
|
||||
}); err != nil {
|
||||
return fmt.Errorf("Delete repository wiki local copy: %v", err)
|
||||
}
|
||||
|
||||
return os.Rename(UserPath(u.Name), UserPath(newUserName))
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.8.30.0204
|
||||
0.8.31.0205
|
Reference in a new issue