diff options
author | zeripath <art27@cantab.net> | 2019-01-14 02:29:58 +0000 |
---|---|---|
committer | techknowlogick <hello@techknowlogick.com> | 2019-01-13 21:29:58 -0500 |
commit | 6868378673f5bb21eac54719d719557b32448db6 (patch) | |
tree | 561ad952fa24332823d1288b1ff364206f1e4caf /models/repo.go | |
parent | 656456441ca09de27ffb44d7a8042db811ff989e (diff) | |
download | gitea-6868378673f5bb21eac54719d719557b32448db6.tar.gz gitea-6868378673f5bb21eac54719d719557b32448db6.zip |
Ensure that sessions are passed into queries that could use the database to prevent deadlocks (#5718)
* Fixed deadlock in CreateComment
* Fix possible deadlock in UpdateIssueDeadline from createDeadlineComment
* Ensure that calls to IsTimeTracker enabled are called within session
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Ensure that calls to reactionList are also called within session
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Ensure all calls in NewPullRequest with the session are called within the session
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Deal with potential deadlocks in repo
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Ensure that isStaring is checked within our transaction
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Fix mistake in isOrganizationMember
Sorry.
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/models/repo.go b/models/repo.go index cd861d7500..86d3e44a1f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -776,7 +776,11 @@ func (repo *Repository) UpdateLocalCopyBranch(branch string) error { // PatchPath returns corresponding patch file path of repository by given issue ID. func (repo *Repository) PatchPath(index int64) (string, error) { - if err := repo.GetOwner(); err != nil { + return repo.patchPath(x, index) +} + +func (repo *Repository) patchPath(e Engine, index int64) (string, error) { + if err := repo.getOwner(e); err != nil { return "", err } @@ -785,7 +789,11 @@ func (repo *Repository) PatchPath(index int64) (string, error) { // SavePatch saves patch data to corresponding location by given issue ID. func (repo *Repository) SavePatch(index int64, patch []byte) error { - patchPath, err := repo.PatchPath(index) + return repo.savePatch(x, index, patch) +} + +func (repo *Repository) savePatch(e Engine, index int64, patch []byte) error { + patchPath, err := repo.patchPath(e, index) if err != nil { return fmt.Errorf("PatchPath: %v", err) } @@ -1479,7 +1487,7 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error collaboration := &Collaboration{RepoID: repo.ID} for _, c := range collaborators { if c.ID != newOwner.ID { - isMember, err := newOwner.IsOrgMember(c.ID) + isMember, err := isOrganizationMember(sess, newOwner.ID, c.ID) if err != nil { return fmt.Errorf("IsOrgMember: %v", err) } else if !isMember { @@ -1536,12 +1544,12 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error if err = os.Rename(RepoPath(owner.Name, repo.Name), RepoPath(newOwner.Name, repo.Name)); err != nil { return fmt.Errorf("rename repository directory: %v", err) } - RemoveAllWithNotice("Delete repository local copy", repo.LocalCopyPath()) + removeAllWithNotice(sess, "Delete repository local copy", repo.LocalCopyPath()) // Rename remote wiki repository to new path and delete local copy. wikiPath := WikiPath(owner.Name, repo.Name) if com.IsExist(wikiPath) { - RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath()) + removeAllWithNotice(sess, "Delete repository wiki local copy", repo.LocalWikiPath()) if err = os.Rename(wikiPath, WikiPath(newOwner.Name, repo.Name)); err != nil { return fmt.Errorf("rename repository wiki: %v", err) } |