Fix: file should be deleted when callback return error

pull/247/head
HFO4 5 years ago
parent f7ecbce64c
commit b862ddb666

@ -46,7 +46,10 @@ func (fs *FileSystem) AddFile(ctx context.Context, parent *model.Folder) (*model
// 添加文件记录前的钩子
err := fs.Trigger(ctx, "BeforeAddFile")
if err != nil {
return nil, err
if err := fs.Trigger(ctx, "BeforeAddFileFailed"); err != nil {
util.Log().Debug("BeforeAddFileFailed 钩子执行失败,%s", err)
}
return nil, ErrFileExisted.WithError(err)
}
file := ctx.Value(fsctx.FileHeaderCtx).(FileHeader)

@ -82,6 +82,8 @@ func ProcessCallback(service CallbackProcessService, c *gin.Context) serializer.
fs.Use("BeforeAddFile", filesystem.HookValidateFile)
fs.Use("BeforeAddFile", filesystem.HookValidateCapacity)
fs.Use("AfterValidateFailed", filesystem.HookGiveBackCapacity)
fs.Use("AfterValidateFailed", filesystem.HookDeleteTempFile)
fs.Use("BeforeAddFileFailed", filesystem.HookDeleteTempFile)
// 向数据库中添加文件
file, err := fs.AddFile(ctx, parentFolder)

Loading…
Cancel
Save