Fix: unexpected querying all files when deleting an empty folder (#1469)

pull/1491/head
topjohncian 2 years ago committed by GitHub
parent b1685d2863
commit 88e10aeaa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -186,6 +186,10 @@ func RemoveFilesWithSoftLinks(files []File) ([]File, error) {
// 结果值 // 结果值
filteredFiles := make([]File, 0) filteredFiles := make([]File, 0)
if len(files) == 0 {
return filteredFiles, nil
}
// 查询软链接的文件 // 查询软链接的文件
var filesWithSoftLinks []File var filesWithSoftLinks []File
tx := DB tx := DB

@ -257,6 +257,19 @@ func TestFile_GetPolicy(t *testing.T) {
} }
} }
func TestRemoveFilesWithSoftLinks_EmptyArg(t *testing.T) {
asserts := assert.New(t)
// 传入空
{
mock.ExpectQuery("SELECT(.+)files(.+)")
file, err := RemoveFilesWithSoftLinks([]File{})
asserts.Error(mock.ExpectationsWereMet())
asserts.NoError(err)
asserts.Equal(len(file), 0)
DB.Find(&File{})
}
}
func TestRemoveFilesWithSoftLinks(t *testing.T) { func TestRemoveFilesWithSoftLinks(t *testing.T) {
asserts := assert.New(t) asserts := assert.New(t)
files := []File{ files := []File{

Loading…
Cancel
Save