aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-02-05 14:11:53 -0500
committerUnknwon <u@gogs.io>2016-02-05 14:11:53 -0500
commitf8182ac5216153f9ac6dbfe31437b03ddadbf286 (patch)
treea18bc6c2e250fc4b39f85c0427ab3b5ddb9b21c3 /models/repo.go
parent4e96a4a62b1bfbe07bc97e75478c1289f6b4d5a9 (diff)
downloadgitea-f8182ac5216153f9ac6dbfe31437b03ddadbf286.tar.gz
gitea-f8182ac5216153f9ac6dbfe31437b03ddadbf286.zip
#2558 delete local wiki copy when rename repo and user
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go32
1 files changed, 12 insertions, 20 deletions
diff --git a/models/repo.go b/models/repo.go
index 868498bc8d..f838de7eaa 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -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 {