repo: delete local copies on owner name change (#5843)

* Protect local repo copy deletion with repoWorkingPool, and delete the local
copy on owner name change.

* Update internal/db/user.go

Co-Authored-By: Unknwon <u@gogs.io>

* Error format on local repo and wiki deletion
This commit is contained in:
Guy Smoilov
2019-11-03 21:07:40 +02:00
committed by Unknwon
parent 97772f406d
commit b40b85e006
2 changed files with 13 additions and 4 deletions

View File

@@ -667,13 +667,15 @@ func ChangeUserName(u *User, newUserName string) (err error) {
return fmt.Errorf("ChangeUsernameInPullRequests: %v", err)
}
// Delete all local copies of repository wiki that user owns.
// Delete all local copies of repositories and wikis the user owns.
if err = x.Where("owner_id=?", u.ID).Iterate(new(Repository), func(idx int, bean interface{}) error {
repo := bean.(*Repository)
deleteRepoLocalCopy(repo)
// TODO: By the same reasoning, shouldn't we also sync access to the local wiki path?
RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
return nil
}); err != nil {
return fmt.Errorf("Delete repository wiki local copy: %v", err)
return fmt.Errorf("delete repository and wiki local copy: %v", err)
}
// Rename or create user base directory