Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deadlock in updateRepository #1813

Merged
merged 1 commit into from
May 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,18 +619,22 @@ func (repo *Repository) IsOwnedBy(userID int64) bool {
return repo.OwnerID == userID
}

// UpdateSize updates the repository size, calculating it using git.GetRepoSize
func (repo *Repository) UpdateSize() error {
func (repo *Repository) updateSize(e Engine) error {
repoInfoSize, err := git.GetRepoSize(repo.RepoPath())
if err != nil {
return fmt.Errorf("UpdateSize: %v", err)
}

repo.Size = repoInfoSize.Size + repoInfoSize.SizePack
_, err = x.ID(repo.ID).Cols("size").Update(repo)
_, err = e.Id(repo.ID).Cols("size").Update(repo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ID is better than Id

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ID is not in the Engine interface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Let's do that later!

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.
func (repo *Repository) CanBeForked() bool {
return !repo.IsBare
Expand Down Expand Up @@ -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)
}
}
Expand Down