Fix renames over redirects (#6216)

In #6211, we started creating repo_redirects for ownership transfers,
however that opens an edge case where a user might perform the
following sequence:

rename org1/repo1 -> org1/repo2  (creates org1/repo1 redirect)
transfer org2/repo1 -> org1/repo1 (org1/repo1 redirect continues to exist)
rename org1/repo1 -> org1/repo3 (fails due to existing org1/repo1 redirect)

This change ensures that each time we rename or transfer a repo,
we delete any existing redirects at the target location.  This
already happens when a new repo is created.  By doing this we ensure
that we'll never have both a repo and a redirect at the same location.

Signed-off-by: James E. Blair <jeblair@redhat.com>
This commit is contained in:
James E. Blair 2019-03-02 05:07:19 -08:00 committed by Lauris BH
parent b28e527a2b
commit a5604b1611
1 changed files with 17 additions and 1 deletions

View File

@ -1564,6 +1564,11 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
} }
} }
// If there was previously a redirect at this location, remove it.
if err = deleteRepoRedirect(sess, newOwner.ID, repo.Name); err != nil {
return fmt.Errorf("delete repo redirect: %v", err)
}
return sess.Commit() return sess.Commit()
} }
@ -1614,7 +1619,18 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error)
RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath()) RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
} }
return nil sess := x.NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
return fmt.Errorf("sess.Begin: %v", err)
}
// If there was previously a redirect at this location, remove it.
if err = deleteRepoRedirect(sess, u.ID, newRepoName); err != nil {
return fmt.Errorf("delete repo redirect: %v", err)
}
return sess.Commit()
} }
func getRepositoriesByForkID(e Engine, forkID int64) ([]*Repository, error) { func getRepositoriesByForkID(e Engine, forkID int64) ([]*Repository, error) {