Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package migrations
  5. import (
  6. "os"
  7. "code.gitea.io/gitea/models"
  8. "xorm.io/builder"
  9. "xorm.io/xorm"
  10. )
  11. func removeAttachmentMissedRepo(x *xorm.Engine) error {
  12. type Attachment struct {
  13. UUID string `xorm:"uuid"`
  14. }
  15. var start int
  16. attachments := make([]*Attachment, 0, 50)
  17. for {
  18. err := x.Select("uuid").Where(builder.NotIn("release_id", builder.Select("id").From("`release`"))).
  19. And("release_id > 0").
  20. OrderBy("id").Limit(50, start).Find(&attachments)
  21. if err != nil {
  22. return err
  23. }
  24. for i := 0; i < len(attachments); i++ {
  25. os.RemoveAll(models.AttachmentLocalPath(attachments[i].UUID))
  26. }
  27. if len(attachments) < 50 {
  28. break
  29. }
  30. start += 50
  31. attachments = attachments[:0]
  32. }
  33. _, err := x.Exec("DELETE FROM attachment WHERE release_id > 0 AND release_id NOT IN (SELECT id FROM `release`)")
  34. return err
  35. }