Skip to content

Commit

Permalink
Check Mirror exists before linking its Repo (go-gitea#20840)
Browse files Browse the repository at this point in the history
In MirrorRepositoryList.loadAttributes there is some code to load the Mirror entries
from the database. This assumes that every Repository which has IsMirror set has
a Mirror associated in the DB. This association is incorrect in the case of
Mirror repository under creation when there is no Mirror entry in the DB until
completion.

Unfortunately LoadAttributes makes this incorrect assumption and presumes that a
Mirror will always be loaded. This then causes a panic.

This PR simply double checks if there a Mirror before attempting to link back to
its Repo. Unfortunately it should be expected that there may be other cases where
this incorrect assumption causes further problems.

Fix go-gitea#20804

Signed-off-by: Andrew Thornton <art27@cantab.net>

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
  • Loading branch information
zeripath and lunny committed Aug 18, 2022
1 parent b43d7e1 commit cc347b1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion models/repo/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ func (repos MirrorRepositoryList) loadAttributes(ctx context.Context) error {
}
for i := range repos {
repos[i].Mirror = set[repos[i].ID]
repos[i].Mirror.Repo = repos[i]
if repos[i].Mirror != nil {
repos[i].Mirror.Repo = repos[i]
}
}
return nil
}
Expand Down

0 comments on commit cc347b1

Please sign in to comment.