-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Delete releases attachments if release is deleted #6068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lafriks
merged 16 commits into
go-gitea:master
from
adelowo:delete_releases_attachments_if_release_is_deleted
Sep 22, 2019
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4ac0923
delete attachments from the database and file system
adelowo c632e48
add migration
adelowo 7b3510f
fix import statements
adelowo 7b8c816
fix package name
adelowo 797f275
Merge remote-tracking branch 'origin' into delete_releases_attachment…
adelowo c1908f4
remove conditional should in case the confi has been changed and the …
adelowo c228842
Merge branch 'master' of github.com:go-gitea/gitea into delete_releas…
adelowo 7832a9a
simplify deletion of attachments in DB
adelowo 9355bbc
fix CI build
adelowo 7063bf3
fix review
adelowo cf713a4
fix merge conflicts
adelowo c59b9d6
add copyright in the proper place
adelowo f018f87
Merge remote-tracking branch 'origin' into delete_releases_attachment…
adelowo e094f75
fix review
adelowo d26a10c
Merge branch 'master' into delete_releases_attachments_if_release_is_…
adelowo 889dff6
Merge branch 'master' into delete_releases_attachments_if_release_is_…
adelowo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,4 @@ func addIsLockedToIssues(x *xorm.Engine) error { | |
} | ||
|
||
return x.Sync2(new(Issue)) | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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.Database.IterateBufferSize). | ||
Where("`comment_id` = 0 and (`release_id` = 0 or `release_id` not in (select `id` from `release`))").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.ID(attachment.ID).NoAutoCondition().Delete(attachment) | ||
return err | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return sess.Commit() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.