Fix deadlock in updateRepository (#1813)

This commit is contained in:
Ethan Koenig 2017-05-26 01:08:13 -04:00 committed by Lunny Xiao
parent 0c332f0480
commit 9c66d1d9ea

View File

@ -619,18 +619,22 @@ func (repo *Repository) IsOwnedBy(userID int64) bool {
return repo.OwnerID == userID return repo.OwnerID == userID
} }
// UpdateSize updates the repository size, calculating it using git.GetRepoSize func (repo *Repository) updateSize(e Engine) error {
func (repo *Repository) UpdateSize() error {
repoInfoSize, err := git.GetRepoSize(repo.RepoPath()) repoInfoSize, err := git.GetRepoSize(repo.RepoPath())
if err != nil { if err != nil {
return fmt.Errorf("UpdateSize: %v", err) return fmt.Errorf("UpdateSize: %v", err)
} }
repo.Size = repoInfoSize.Size + repoInfoSize.SizePack repo.Size = repoInfoSize.Size + repoInfoSize.SizePack
_, err = x.ID(repo.ID).Cols("size").Update(repo) _, err = e.Id(repo.ID).Cols("size").Update(repo)
return err return err
} }
// UpdateSize updates the repository size, calculating it using git.GetRepoSize
func (repo *Repository) UpdateSize() error {
return repo.updateSize(x)
}
// CanBeForked returns true if repository meets the requirements of being forked. // CanBeForked returns true if repository meets the requirements of being forked.
func (repo *Repository) CanBeForked() bool { func (repo *Repository) CanBeForked() bool {
return !repo.IsBare return !repo.IsBare
@ -1554,7 +1558,7 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
} }
} }
if err = repo.UpdateSize(); err != nil { if err = repo.updateSize(e); err != nil {
log.Error(4, "Failed to update size for repository: %v", err) log.Error(4, "Failed to update size for repository: %v", err)
} }
} }