#2558 delete local wiki copy when rename repo and user
This commit is contained in:
parent
4e96a4a62b
commit
f8182ac521
@ -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)
|
![](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 |
|
| Web | UI | Preview |
|
||||||
|:-------------:|:-------:|:-------:|
|
|:-------------:|:-------:|:-------:|
|
||||||
|
2
gogs.go
2
gogs.go
@ -17,7 +17,7 @@ import (
|
|||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.8.30.0204"
|
const APP_VER = "0.8.31.0205"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
@ -5,12 +5,15 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
|
|
||||||
"github.com/gogits/gogs/modules/base"
|
"github.com/gogits/gogs/modules/base"
|
||||||
|
"github.com/gogits/gogs/modules/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NoticeType int
|
type NoticeType int
|
||||||
@ -47,6 +50,18 @@ func CreateRepositoryNotice(desc string) error {
|
|||||||
return CreateNotice(NOTICE_REPOSITORY, desc)
|
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.
|
// CountNotices returns number of notices.
|
||||||
func CountNotices() int64 {
|
func CountNotices() int64 {
|
||||||
count, _ := x.Count(new(Notice))
|
count, _ := x.Count(new(Notice))
|
||||||
|
@ -1123,16 +1123,22 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error)
|
|||||||
return ErrRepoAlreadyExist{u.Name, newRepoName}
|
return ErrRepoAlreadyExist{u.Name, newRepoName}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repo, err := GetRepositoryByName(u.Id, oldRepoName)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("GetRepositoryByName: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Change repository directory name.
|
// 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)
|
return fmt.Errorf("rename repository directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wikiPath := WikiPath(u.Name, oldRepoName)
|
wikiPath := repo.WikiPath()
|
||||||
if com.IsExist(wikiPath) {
|
if com.IsExist(wikiPath) {
|
||||||
if err = os.Rename(wikiPath, WikiPath(u.Name, newRepoName)); err != nil {
|
if err = os.Rename(wikiPath, WikiPath(u.Name, newRepoName)); err != nil {
|
||||||
return fmt.Errorf("rename repository wiki: %v", err)
|
return fmt.Errorf("rename repository wiki: %v", err)
|
||||||
}
|
}
|
||||||
|
RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -1295,30 +1301,16 @@ func DeleteRepository(uid, repoID int64) error {
|
|||||||
|
|
||||||
// Remove repository files.
|
// Remove repository files.
|
||||||
repoPath := repo.repoPath(sess)
|
repoPath := repo.repoPath(sess)
|
||||||
if err = os.RemoveAll(repoPath); err != nil {
|
RemoveAllWithNotice("Delete repository files", repoPath)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wikiPaths := []string{repo.WikiPath(), repo.LocalWikiPath()}
|
wikiPaths := []string{repo.WikiPath(), repo.LocalWikiPath()}
|
||||||
for _, wikiPath := range wikiPaths {
|
for _, wikiPath := range wikiPaths {
|
||||||
if err = os.RemoveAll(wikiPath); err != nil {
|
RemoveAllWithNotice("Delete repository wiki", wikiPath)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove attachment files.
|
// Remove attachment files.
|
||||||
for i := range attachmentPaths {
|
for i := range attachmentPaths {
|
||||||
if err = os.Remove(attachmentPaths[i]); err != nil {
|
RemoveAllWithNotice("Delete attachment", attachmentPaths[i])
|
||||||
log.Warn("delete attachment: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = sess.Commit(); err != nil {
|
if err = sess.Commit(); err != nil {
|
||||||
@ -1333,7 +1325,7 @@ func DeleteRepository(uid, repoID int64) error {
|
|||||||
}
|
}
|
||||||
for i := range forkRepos {
|
for i := range forkRepos {
|
||||||
if err = DeleteRepository(forkRepos[i].OwnerID, forkRepos[i].ID); err != nil {
|
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 {
|
} else {
|
||||||
|
@ -598,11 +598,19 @@ func ChangeUserName(u *User, newUserName string) (err error) {
|
|||||||
return ErrUserAlreadyExist{newUserName}
|
return ErrUserAlreadyExist{newUserName}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ChangeUsernameInPullRequests(u.Name, newUserName)
|
if err = ChangeUsernameInPullRequests(u.Name, newUserName); err != nil {
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("ChangeUsernameInPullRequests: %v", err)
|
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))
|
return os.Rename(UserPath(u.Name), UserPath(newUserName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
0.8.30.0204
|
0.8.31.0205
|
Loading…
Reference in New Issue
Block a user