Skip to content

Commit b12ed0b

Browse files
earl-warrenGusted
authored andcommitted
Initalize stroage for orphaned repository doctor (go-gitea#28487)
- 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]>
1 parent 2c2e008 commit b12ed0b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

modules/doctor/repository.go

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"code.gitea.io/gitea/models/db"
1010
user_model "code.gitea.io/gitea/models/user"
1111
"code.gitea.io/gitea/modules/log"
12+
"code.gitea.io/gitea/modules/storage"
1213
repo_service "code.gitea.io/gitea/services/repository"
1314

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

3233
// deleteOrphanedRepos delete repository where user of owner_id do not exist
3334
func deleteOrphanedRepos(ctx context.Context) (int64, error) {
35+
if err := storage.Init(); err != nil {
36+
return 0, err
37+
}
38+
3439
batchSize := db.MaxBatchInsertSize("repository")
3540
e := db.GetEngine(ctx)
3641
var deleted int64

0 commit comments

Comments
 (0)