diff options
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/models/repo.go b/models/repo.go index f2453cc5c7..b11671e1fc 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1511,26 +1511,27 @@ func UpdateRepositoryUnits(repo *Repository, units []RepoUnit, deleteUnitTypes [ } // DeleteRepository deletes a repository for a user or organization. +// make sure if you call this func to close open sessions (sqlite will otherwise get a deadlock) func DeleteRepository(doer *User, uid, repoID int64) error { + sess := x.NewSession() + defer sess.Close() + if err := sess.Begin(); err != nil { + return err + } + // In case is a organization. - org, err := GetUserByID(uid) + org, err := getUserByID(sess, uid) if err != nil { return err } if org.IsOrganization() { - if err = org.GetTeams(&SearchTeamOptions{}); err != nil { + if err = org.getTeams(sess); err != nil { return err } } - sess := x.NewSession() - defer sess.Close() - if err = sess.Begin(); err != nil { - return err - } - - repo := &Repository{ID: repoID, OwnerID: uid} - has, err := sess.Get(repo) + repo := &Repository{OwnerID: uid} + has, err := sess.ID(repoID).Get(repo) if err != nil { return err } else if !has { @@ -1679,14 +1680,7 @@ func DeleteRepository(doer *User, uid, repoID int64) error { } if err = sess.Commit(); err != nil { - sess.Close() - if len(deployKeys) > 0 { - // We need to rewrite the public keys because the commit failed - if err2 := RewriteAllPublicKeys(); err2 != nil { - return fmt.Errorf("Commit: %v SSH Keys: %v", err, err2) - } - } - return fmt.Errorf("Commit: %v", err) + return err } sess.Close() |