Fix: storage policy should be re-dispatched according to policy id in upload session

This commit is contained in:
HFO4
2020-01-17 14:35:21 +08:00
parent b862ddb666
commit 68d4a86166
8 changed files with 22 additions and 45 deletions

View File

@@ -105,7 +105,7 @@ func (fs *FileSystem) doCompress(ctx context.Context, file *model.File, folder *
if file != nil {
// 切换上传策略
fs.Policy = file.GetPolicy()
err := fs.dispatchHandler()
err := fs.DispatchHandler()
if err != nil {
util.Log().Warning("无法压缩文件%s%s", file.Name, err)
return

View File

@@ -79,7 +79,7 @@ func (fs *FileSystem) AddFile(ctx context.Context, parent *model.Folder) (*model
func (fs *FileSystem) GetPhysicalFileContent(ctx context.Context, path string) (response.RSCloser, error) {
// 重设上传策略
fs.Policy = &model.Policy{Type: "local"}
_ = fs.dispatchHandler()
_ = fs.DispatchHandler()
// 获取文件流
rs, err := fs.Handler.Get(ctx, path)
@@ -184,7 +184,7 @@ func (fs *FileSystem) deleteGroupedFile(ctx context.Context, files map[uint][]*m
// 切换上传策略
fs.Policy = toBeDeletedFiles[0].GetPolicy()
err := fs.dispatchHandler()
err := fs.DispatchHandler()
if err != nil {
failed[policyID] = sourceNames
continue
@@ -327,7 +327,7 @@ func (fs *FileSystem) resetPolicyToFirstFile(ctx context.Context) error {
}
fs.Policy = fs.FileTarget[0].GetPolicy()
err := fs.dispatchHandler()
err := fs.DispatchHandler()
if err != nil {
return err
}

View File

@@ -109,7 +109,7 @@ func NewFileSystem(user *model.User) (*FileSystem, error) {
fs := getEmptyFS()
fs.User = user
// 分配存储策略适配器
err := fs.dispatchHandler()
err := fs.DispatchHandler()
// TODO 分配默认钩子
return fs, err
@@ -135,9 +135,9 @@ func NewAnonymousFileSystem() (*FileSystem, error) {
return fs, nil
}
// dispatchHandler 根据存储策略分配文件适配器
// DispatchHandler 根据存储策略分配文件适配器
// TODO 完善测试
func (fs *FileSystem) dispatchHandler() error {
func (fs *FileSystem) DispatchHandler() error {
var policyType string
var currentPolicy *model.Policy

View File

@@ -64,13 +64,13 @@ func TestDispatchHandler(t *testing.T) {
}
// 未指定,使用用户默认
err := fs.dispatchHandler()
err := fs.DispatchHandler()
asserts.NoError(err)
asserts.IsType(local.Driver{}, fs.Handler)
// 已指定,发生错误
fs.Policy = &model.Policy{Type: "unknown"}
err = fs.dispatchHandler()
err = fs.DispatchHandler()
asserts.Error(err)
}

View File

@@ -106,7 +106,7 @@ func HookResetPolicy(ctx context.Context, fs *FileSystem) error {
}
fs.Policy = originFile.GetPolicy()
return fs.dispatchHandler()
return fs.DispatchHandler()
}
// HookValidateCapacity 验证并扣除用户容量,包含数据库操作