Skip to content

Commit

Permalink
Initalize stroage for orphaned repository doctor (go-gitea#28487)
Browse files Browse the repository at this point in the history
- When a repository is orphaned and has objects stored in any of the
storages such as repository avatar or attachments the delete function
would error, because the storage module wasn't initalized.
- Add code to initialize the storage module.

Refs: https://codeberg.org/forgejo/forgejo/pulls/1954

Co-authored-by: Gusted <[email protected]>
  • Loading branch information
2 people authored and silverwind committed Feb 20, 2024
1 parent 2a1dc23 commit 1a041a4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/doctor/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/storage"
repo_service "code.gitea.io/gitea/services/repository"

"xorm.io/builder"
Expand All @@ -31,6 +32,10 @@ func countOrphanedRepos(ctx context.Context) (int64, error) {

// deleteOrphanedRepos delete repository where user of owner_id do not exist
func deleteOrphanedRepos(ctx context.Context) (int64, error) {
if err := storage.Init(); err != nil {
return 0, err
}

batchSize := db.MaxBatchInsertSize("repository")
e := db.GetEngine(ctx)
var deleted int64
Expand Down

0 comments on commit 1a041a4

Please sign in to comment.