ignore some errors on repairAllRepos (#2792)

close  #2791

Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
This commit is contained in:
6543 2023-12-13 14:53:38 +01:00 committed by GitHub
parent c6ce23e933
commit 4974d4cffe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -412,8 +412,10 @@ func DeleteRepo(c *gin.Context) {
// @Param repo_id path int true "the repository id"
func RepairRepo(c *gin.Context) {
repo := session.Repo(c)
repairRepo(c, repo, true)
repairRepo(c, repo, true, false)
if c.Writer.Written() {
return
}
c.Status(http.StatusNoContent)
}
@ -544,7 +546,7 @@ func RepairAllRepos(c *gin.Context) {
}
for _, r := range repos {
repairRepo(c, r, false)
repairRepo(c, r, false, true)
if c.Writer.Written() {
return
}
@ -553,13 +555,20 @@ func RepairAllRepos(c *gin.Context) {
c.Status(http.StatusNoContent)
}
func repairRepo(c *gin.Context, repo *model.Repo, withPerms bool) {
func repairRepo(c *gin.Context, repo *model.Repo, withPerms, skipOnErr bool) {
forge := server.Config.Services.Forge
_store := store.FromContext(c)
user, err := _store.GetUser(repo.UserID)
if err != nil {
handleDbError(c, err)
if errors.Is(err, types.RecordNotExist) {
if !skipOnErr {
c.AbortWithStatus(http.StatusNotFound)
}
log.Error().Err(err).Msgf("could not get user on repo repair")
} else {
_ = c.AbortWithError(http.StatusInternalServerError, err)
}
return
}
@ -582,7 +591,9 @@ func repairRepo(c *gin.Context, repo *model.Repo, withPerms bool) {
from, err := forge.Repo(c, user, repo.ForgeRemoteID, repo.Owner, repo.Name)
if err != nil {
log.Error().Err(err).Msgf("get repo '%s/%s' from forge", repo.Owner, repo.Name)
c.AbortWithStatus(http.StatusInternalServerError)
if !skipOnErr {
c.AbortWithStatus(http.StatusInternalServerError)
}
return
}