Skip to content

Commit 4330b6e

Browse files
committed
fix bug
1 parent 50b9222 commit 4330b6e

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-
2+
id: 1
3+
storage_name: attachment
4+
path_type: 1
5+
relative_path: "1/2/1213b3ce-b1af-4a82-9279-bc30ea91aa45"
6+
created_unix: 1234567890
File renamed without changes.

services/attachment/attachment_test.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,19 @@ import (
88
"path/filepath"
99
"strings"
1010
"testing"
11-
"time"
1211

12+
_ "code.gitea.io/gitea/models/actions"
1313
"code.gitea.io/gitea/models/db"
1414
repo_model "code.gitea.io/gitea/models/repo"
15+
"code.gitea.io/gitea/models/system"
1516
"code.gitea.io/gitea/models/unittest"
1617
user_model "code.gitea.io/gitea/models/user"
1718
"code.gitea.io/gitea/modules/storage"
18-
19-
_ "code.gitea.io/gitea/models/actions"
19+
storage_service "code.gitea.io/gitea/services/storage"
2020

2121
"github.com/stretchr/testify/assert"
2222
)
2323

24-
func TestMain(m *testing.M) {
25-
unittest.MainTest(m)
26-
}
27-
2824
func TestUploadAttachment(t *testing.T) {
2925
assert.NoError(t, unittest.PrepareTestDatabase())
3026

@@ -59,16 +55,28 @@ func TestDeleteAttachments(t *testing.T) {
5955
assert.NoError(t, err)
6056
assert.Equal(t, attachment8.Size, fileInfo.Size())
6157

62-
err = DeleteAttachment(db.DefaultContext, attachment8)
58+
deletionsTotal, err := db.Count[system.StoragePathDeletion](t.Context(), db.ListOptionsAll)
59+
assert.NoError(t, err)
60+
assert.Equal(t, int64(1), deletionsTotal)
61+
62+
err = DeleteAttachment(t.Context(), attachment8)
6363
assert.NoError(t, err)
6464

65-
attachment, err := repo_model.GetAttachmentByUUID(db.DefaultContext, attachment8.UUID)
65+
attachment, err := repo_model.GetAttachmentByUUID(t.Context(), attachment8.UUID)
6666
assert.Error(t, err)
6767
assert.True(t, repo_model.IsErrAttachmentNotExist(err))
6868
assert.Nil(t, attachment)
6969

70-
// allow the queue to process the deletion
71-
time.Sleep(1 * time.Second)
70+
deletions, err := db.Find[system.StoragePathDeletion](t.Context(), db.ListOptionsAll)
71+
assert.NoError(t, err)
72+
assert.Len(t, deletions, int(deletionsTotal)+1)
73+
assert.Equal(t, attachment8.RelativePath(), deletions[deletionsTotal].RelativePath)
74+
75+
_, err = storage.Attachments.Stat(attachment8.RelativePath())
76+
assert.NoError(t, err)
77+
78+
err = storage_service.ScanToBeDeletedFilesOrDir(t.Context())
79+
assert.NoError(t, err)
7280

7381
_, err = storage.Attachments.Stat(attachment8.RelativePath())
7482
assert.Error(t, err)

services/attachment/main_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package attachment
5+
6+
import (
7+
"testing"
8+
9+
"code.gitea.io/gitea/models/unittest"
10+
)
11+
12+
func TestMain(m *testing.M) {
13+
unittest.MainTest(m)
14+
}

services/storage/cleanup.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func ScanToBeDeletedFilesOrDir(ctx context.Context) error {
5858
lastID := int64(0)
5959
for {
6060
if err := db.GetEngine(ctx).
61+
Table("storage_path_deletion").
6162
Select("id").
6263
Where("id > ?", lastID).
6364
Asc("id").

0 commit comments

Comments
 (0)