diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/admin.go | 24 | ||||
-rw-r--r-- | models/issue.go | 1 | ||||
-rw-r--r-- | models/repo.go | 32 | ||||
-rw-r--r-- | models/user.go | 12 |
4 files changed, 47 insertions, 22 deletions
diff --git a/models/admin.go b/models/admin.go index 1d6bf62961..7756cd6ae2 100644 --- a/models/admin.go +++ b/models/admin.go @@ -5,12 +5,17 @@ package models import ( + "fmt" + "os" + "os/exec" "strings" "time" "github.com/Unknwon/com" "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/log" + "github.com/gogits/gogs/modules/setting" ) type NoticeType int @@ -47,6 +52,25 @@ 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) { + var err error + if setting.IsWindows { + err = exec.Command("cmd", "/C", "rmdir", "/S", "/Q", path).Run() + } else { + err = os.RemoveAll(path) + } + + if 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)) diff --git a/models/issue.go b/models/issue.go index 6188da5c63..326454630e 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1179,6 +1179,7 @@ func (m *Milestone) AfterSet(colName string, _ xorm.Cell) { if m.Deadline.Year() == 9999 { return } + m.Deadline = regulateTimeZone(m.Deadline) m.DeadlineString = m.Deadline.Format("2006-01-02") if time.Now().After(m.Deadline) { 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 { diff --git a/models/user.go b/models/user.go index 23ed5ae8d2..09ad74d76d 100644 --- a/models/user.go +++ b/models/user.go @@ -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)) } |