mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
feat(dashboard): unlink file while not deleting its physical source (#789)
This commit is contained in:
@@ -120,8 +120,9 @@ func (fs *FileSystem) Move(ctx context.Context, dirs, files []uint, src, dst str
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete 递归删除对象, force 为 true 时强制删除文件记录,忽略物理删除是否成功
|
||||
func (fs *FileSystem) Delete(ctx context.Context, dirs, files []uint, force bool) error {
|
||||
// Delete 递归删除对象, force 为 true 时强制删除文件记录,忽略物理删除是否成功;
|
||||
// unlink 为 true 时只删除虚拟文件系统的文件记录,不删除物理文件。
|
||||
func (fs *FileSystem) Delete(ctx context.Context, dirs, files []uint, force, unlink bool) error {
|
||||
// 已删除的文件ID
|
||||
var deletedFiles = make([]*model.File, 0, len(fs.FileTarget))
|
||||
// 删除失败的文件的父目录ID
|
||||
@@ -155,7 +156,10 @@ func (fs *FileSystem) Delete(ctx context.Context, dirs, files []uint, force bool
|
||||
policyGroup := fs.GroupFileByPolicy(ctx, filesToBeDelete)
|
||||
|
||||
// 按照存储策略分组删除对象
|
||||
failed := fs.deleteGroupedFile(ctx, policyGroup)
|
||||
failed := make(map[uint][]string)
|
||||
if !unlink {
|
||||
failed = fs.deleteGroupedFile(ctx, policyGroup)
|
||||
}
|
||||
|
||||
// 整理删除结果
|
||||
for i := 0; i < len(fs.FileTarget); i++ {
|
||||
|
||||
@@ -3,13 +3,13 @@ package filesystem
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem/response"
|
||||
testMock "github.com/stretchr/testify/mock"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
model "github.com/cloudreve/Cloudreve/v3/models"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/cache"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/conf"
|
||||
@@ -505,7 +505,7 @@ func TestFileSystem_Delete(t *testing.T) {
|
||||
|
||||
fs.FileTarget = []model.File{}
|
||||
fs.DirTarget = []model.Folder{}
|
||||
err := fs.Delete(ctx, []uint{1}, []uint{1}, true)
|
||||
err := fs.Delete(ctx, []uint{1}, []uint{1}, true, false)
|
||||
asserts.NoError(err)
|
||||
}
|
||||
//全部成功
|
||||
@@ -563,7 +563,7 @@ func TestFileSystem_Delete(t *testing.T) {
|
||||
|
||||
fs.FileTarget = []model.File{}
|
||||
fs.DirTarget = []model.Folder{}
|
||||
err = fs.Delete(ctx, []uint{1}, []uint{1}, false)
|
||||
err = fs.Delete(ctx, []uint{1}, []uint{1}, false, false)
|
||||
asserts.NoError(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user