parent
5ee09d3c81
commit
cf20ebc8ba
5 changed files with 38 additions and 31 deletions
|
@ -1600,26 +1600,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 {
|
||||
|
@ -1768,14 +1769,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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue