aboutsummaryrefslogtreecommitdiffstats
path: root/models/admin
diff options
context:
space:
mode:
Diffstat (limited to 'models/admin')
-rw-r--r--models/admin/notice.go33
-rw-r--r--models/admin/notice_test.go3
2 files changed, 11 insertions, 25 deletions
diff --git a/models/admin/notice.go b/models/admin/notice.go
index c41e49ed8c..2d71b426dd 100644
--- a/models/admin/notice.go
+++ b/models/admin/notice.go
@@ -43,12 +43,7 @@ func (n *Notice) TrStr() string {
}
// CreateNotice creates new system notice.
-func CreateNotice(tp NoticeType, desc string, args ...interface{}) error {
- return CreateNoticeCtx(db.DefaultContext, tp, desc, args...)
-}
-
-// CreateNoticeCtx creates new system notice.
-func CreateNoticeCtx(ctx context.Context, tp NoticeType, desc string, args ...interface{}) error {
+func CreateNotice(ctx context.Context, tp NoticeType, desc string, args ...interface{}) error {
if len(args) > 0 {
desc = fmt.Sprintf(desc, args...)
}
@@ -61,38 +56,28 @@ func CreateNoticeCtx(ctx context.Context, tp NoticeType, desc string, args ...in
// CreateRepositoryNotice creates new system notice with type NoticeRepository.
func CreateRepositoryNotice(desc string, args ...interface{}) error {
- return CreateNoticeCtx(db.DefaultContext, NoticeRepository, desc, args...)
+ return CreateNotice(db.DefaultContext, NoticeRepository, desc, args...)
}
// RemoveAllWithNotice removes all directories in given path and
// creates a system notice when error occurs.
-func RemoveAllWithNotice(title, path string) {
- RemoveAllWithNoticeCtx(db.DefaultContext, title, path)
-}
-
-// RemoveStorageWithNotice removes a file from the storage and
-// creates a system notice when error occurs.
-func RemoveStorageWithNotice(bucket storage.ObjectStorage, title, path string) {
- removeStorageWithNotice(db.DefaultContext, bucket, title, path)
-}
-
-func removeStorageWithNotice(ctx context.Context, bucket storage.ObjectStorage, title, path string) {
- if err := bucket.Delete(path); err != nil {
+func RemoveAllWithNotice(ctx context.Context, title, path string) {
+ if err := util.RemoveAll(path); err != nil {
desc := fmt.Sprintf("%s [%s]: %v", title, path, err)
log.Warn(title+" [%s]: %v", path, err)
- if err = CreateNoticeCtx(ctx, NoticeRepository, desc); err != nil {
+ if err = CreateNotice(ctx, NoticeRepository, desc); err != nil {
log.Error("CreateRepositoryNotice: %v", err)
}
}
}
-// RemoveAllWithNoticeCtx removes all directories in given path and
+// RemoveStorageWithNotice removes a file from the storage and
// creates a system notice when error occurs.
-func RemoveAllWithNoticeCtx(ctx context.Context, title, path string) {
- if err := util.RemoveAll(path); err != nil {
+func RemoveStorageWithNotice(ctx context.Context, bucket storage.ObjectStorage, title, path string) {
+ if err := bucket.Delete(path); err != nil {
desc := fmt.Sprintf("%s [%s]: %v", title, path, err)
log.Warn(title+" [%s]: %v", path, err)
- if err = CreateNoticeCtx(ctx, NoticeRepository, desc); err != nil {
+ if err = CreateNotice(ctx, NoticeRepository, desc); err != nil {
log.Error("CreateRepositoryNotice: %v", err)
}
}
diff --git a/models/admin/notice_test.go b/models/admin/notice_test.go
index 7272df4368..b4613db8e7 100644
--- a/models/admin/notice_test.go
+++ b/models/admin/notice_test.go
@@ -7,6 +7,7 @@ package admin
import (
"testing"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
@@ -28,7 +29,7 @@ func TestCreateNotice(t *testing.T) {
Description: "test description",
}
unittest.AssertNotExistsBean(t, noticeBean)
- assert.NoError(t, CreateNotice(noticeBean.Type, noticeBean.Description))
+ assert.NoError(t, CreateNotice(db.DefaultContext, noticeBean.Type, noticeBean.Description))
unittest.AssertExistsAndLoadBean(t, noticeBean)
}