From 676431a1d5c4413b826aad31aa925e43169b569b Mon Sep 17 00:00:00 2001 From: 1-6 Date: Tue, 25 Jul 2023 14:14:01 +0800 Subject: [PATCH] x --- core/plugin_core.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/plugin_core.go b/core/plugin_core.go index fcded58..83490d0 100644 --- a/core/plugin_core.go +++ b/core/plugin_core.go @@ -130,19 +130,23 @@ func initPlugins() { Error: errors.New("插件源异常!"), } } - defer resp.Body.Close() zipfile := plugin_dir + "/" + utils.GenUUID() + ".zip" - f, err := os.OpenFile(zipfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755) - if err != nil { - return &storage.Final{ - Error: errors.New("文件异常!"), + err = func() error { + defer resp.Body.Close() + f, err := os.OpenFile(zipfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755) + if err != nil { + return errors.New("下载异常!") } - } - defer f.Close() - _, err = io.Copy(f, resp.Body) + defer f.Close() + _, err = io.Copy(f, resp.Body) + if err != nil { + return errors.New("文件异常!") + } + return nil + }() if err != nil { return &storage.Final{ - Error: errors.New("下载异常!"), + Error: err, } } defer os.Remove(zipfile)