Skip to content

Commit

Permalink
Fix renames over redirects
Browse files Browse the repository at this point in the history
In go-gitea#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 <[email protected]>
  • Loading branch information
James E. Blair committed Mar 1, 2019
1 parent 8e266c3 commit 1bd4c99
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -1614,7 +1619,18 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error)
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) {
Expand Down

0 comments on commit 1bd4c99

Please sign in to comment.