From 0dddc1260949669230bbf9b9ef413b0115fd3a9f Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Mon, 18 Nov 2019 18:29:37 +0800 Subject: [PATCH] Modify: check whether file exist before deleting unfinished uploading --- pkg/filesystem/hook.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/filesystem/hook.go b/pkg/filesystem/hook.go index b87c709..283bf08 100644 --- a/pkg/filesystem/hook.go +++ b/pkg/filesystem/hook.go @@ -3,6 +3,7 @@ package filesystem import ( "context" "errors" + "github.com/HFO4/cloudreve/pkg/util" ) // GenericBeforeUpload 通用上传前处理钩子,包含数据库操作 @@ -33,9 +34,11 @@ func GenericBeforeUpload(ctx context.Context, fs *FileSystem, file FileData) err func GenericAfterUploadCanceled(ctx context.Context, fs *FileSystem, file FileData) error { filePath := ctx.Value("path").(string) // 删除临时文件 - _, err := fs.Handler.Delete(ctx, []string{filePath}) - if err != nil { - return err + if util.Exists(filePath) { + _, err := fs.Handler.Delete(ctx, []string{filePath}) + if err != nil { + return err + } } // 归还用户容量