summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-08-18 03:22:56 +0100
committerGitHub <noreply@github.com>2022-08-18 10:22:56 +0800
commit03df7d04529ad7cfcc5acffb254bb6f168ccbf08 (patch)
treed486bb6c52ebd0c9a6605d9074c91fb0ded242bd /models
parent4a797f8faba0da3881f6de9b4575f713d1860dc6 (diff)
downloadgitea-03df7d04529ad7cfcc5acffb254bb6f168ccbf08.tar.gz
gitea-03df7d04529ad7cfcc5acffb254bb6f168ccbf08.zip
Check Mirror exists before linking its Repo (#20840)
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 #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>
Diffstat (limited to 'models')
-rw-r--r--models/repo/mirror.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/models/repo/mirror.go b/models/repo/mirror.go
index 8f96e8cee1..e94bbda2c1 100644
--- a/models/repo/mirror.go
+++ b/models/repo/mirror.go
@@ -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
}