Skip to content

Commit

Permalink
delete attachments from the database and file system
Browse files Browse the repository at this point in the history
  • Loading branch information
adelowo committed Feb 14, 2019
1 parent 7a72aa6 commit 3a5394b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 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 @@ -469,6 +470,24 @@ func DeleteReleaseByID(id int64, u *User, delTag bool) error {
go HookQueue.Add(rel.Repo.ID)
}

if setting.AttachmentEnabled {

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)
}

if _, err := x.In("uuid", uuids).Delete(new(Attachment)); err != nil {
return err
}
}

return nil
}

Expand Down

0 comments on commit 3a5394b

Please sign in to comment.