Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ var migrations = []Migration{
// v93 -> v94
NewMigration("add email notification enabled preference to user", addEmailNotificationEnabledToUser),
// v94 -> v95
NewMigration("delete orphaned attachments", deleteOrphanedAttachments),
// v95 -> v96
NewMigration("add enable_status_check, status_check_contexts to protected_branch", addStatusCheckColumnsForProtectedBranches),
}

Expand Down
1 change: 0 additions & 1 deletion models/migrations/v80.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ func addIsLockedToIssues(x *xorm.Engine) error {
}

return x.Sync2(new(Issue))

}
4 changes: 3 additions & 1 deletion models/migrations/v94.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

package migrations

import "github.com/go-xorm/xorm"
import (
"github.com/go-xorm/xorm"
)

func addStatusCheckColumnsForProtectedBranches(x *xorm.Engine) error {
type ProtectedBranch struct {
Expand Down
47 changes: 47 additions & 0 deletions models/migrations/v95.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package migrations

import (
"os"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/setting"
"github.com/go-xorm/xorm"
)

func deleteOrphanedAttachments(x *xorm.Engine) error {

type Attachment struct {
ID int64 `xorm:"pk autoincr"`
UUID string `xorm:"uuid UNIQUE"`
IssueID int64 `xorm:"INDEX"`
ReleaseID int64 `xorm:"INDEX"`
CommentID int64
}

sess := x.NewSession()
defer sess.Close()

err := sess.BufferSize(setting.IterateBufferSize).
Where("`comment_id` = 0 and (`release_id` = 0 or `release_id` not in (select `id` from `releases`))").Cols("uuid").
Iterate(new(Attachment),
func(idx int, bean interface{}) error {
attachment := bean.(*Attachment)

if err := os.RemoveAll(models.AttachmentLocalPath(attachment.UUID)); err != nil {
return err
}

_, err := sess.Delete(attachment)
return err
})

if err != nil {
return err
}

return sess.Commit()
}
15 changes: 14 additions & 1 deletion models/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package models

import (
"fmt"
"os"
"sort"
"strings"

Expand Down Expand Up @@ -369,7 +370,19 @@ func DeleteReleaseByID(id int64, doer *User, delTag bool) error {
go HookQueue.Add(rel.Repo.ID)
}

return nil
uuids := make([]string, 0, len(rel.Attachments))

for i := range rel.Attachments {
attachment := rel.Attachments[i]
if err := os.RemoveAll(attachment.LocalPath()); err != nil {
return err
}

uuids = append(uuids, attachment.UUID)
}

_, err := x.Delete(&Attachment{ReleaseID: id})
return err
}

// SyncReleasesWithTags synchronizes release table with repository tags
Expand Down