From 07642fd86de34583052d9467260ec6c30e7ded9e Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期三, 29 七月 2020 20:35:41 +0800 Subject: [PATCH] verify invalid install pack --- service/SdkInstall.go | 36 ++++++++++++++++++++++++++++-------- controllers/sdk.go | 4 +++- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/controllers/sdk.go b/controllers/sdk.go index 3327309..13ea1d7 100644 --- a/controllers/sdk.go +++ b/controllers/sdk.go @@ -280,13 +280,15 @@ // @Produce json // @Tags 绠楁硶 // @Param identifier formData string true "鏁翠釜鏂囦欢鐨勫敮涓�鏍囪瘑锛岀洰鍓嶆槸md5" +// @Param filename formData string true "鏂囦欢鍚嶇О" // @Success 200 {string} json "{"code":200, msg:"", success:true}" // @Failure 500 {string} json "{"code":500, msg:"", success:false}" // @Router /data/api-v/sdk/showInstallInfo [post] func (sc SdkController) ShowInstallInfo(c *gin.Context) { identifier := c.Request.FormValue("identifier") + filename := c.Request.FormValue("filename") var sv service.SdkInstallService - b,d := sv.ShowInstallInfo(identifier) + b,d := sv.ShowInstallInfo(identifier, filename) if b { util.ResponseFormat(c,code.Success, d) } else { diff --git a/service/SdkInstall.go b/service/SdkInstall.go index 3c19e59..b0ed7f6 100644 --- a/service/SdkInstall.go +++ b/service/SdkInstall.go @@ -136,7 +136,7 @@ return true, nil } -func (sv SdkInstallService) ShowInstallInfo(identifier string) (bool, map[string]interface{}) { +func (sv SdkInstallService) ShowInstallInfo(identifier string, filename string) (bool, map[string]interface{}, error) { configPatchPath := "" if config.Server.PatchPath != "" { configPatchPath = config.Server.PatchPath @@ -144,6 +144,26 @@ configPatchPath = "../patch" } unPackTargetPath := configPatchPath+"/"+identifier+"_basic/" + isValid := false + defer func() { + if !isValid { + filenameWithSuffix := path.Base(filename) + ext := path.Ext(filenameWithSuffix) + unPackFilePath := configPatchPath+"/"+identifier+ext + md5DirPath := configPatchPath+"/"+identifier + + if util.Exists(unPackTargetPath) { + os.RemoveAll(unPackTargetPath) + } + if util.Exists(unPackFilePath) { + os.RemoveAll(unPackFilePath) + } + if util.DirExists(md5DirPath) { + go os.RemoveAll(md5DirPath) + } + + } + }() if util.Exists(unPackTargetPath) { targetFileName := "" err := filepath.Walk(unPackTargetPath, func(path string, f os.FileInfo, err error) error { @@ -156,7 +176,7 @@ return nil }) if err != nil { - return false, nil + return isValid, nil, errors.New("闈炴硶鐨勫畨瑁呭寘") } else { unPackPath := unPackTargetPath + targetFileName +"/" //瑙e帇瀹屾垚锛岃幏鍙栧畨瑁呭寘涓殑鏂囦欢锛屽紑濮嬪畨瑁� @@ -170,19 +190,19 @@ "sdkName": ins.ProductName, "installVersion": ins.InstallVersion, "installContent": ins.InstallContent, - } + }, nil } else { - return false, nil + return false, nil, errors.New("闈炴硶鐨勫畨瑁呭寘") } } else { - return false, nil + return false, nil, errors.New("闈炴硶鐨勫畨瑁呭寘") } } else { - return false, nil + return false, nil, errors.New("闈炴硶鐨勫畨瑁呭寘") } } } else { - return false, nil + return isValid, nil, errors.New("瀹夎鍖呭凡涓嶅瓨鍦�") } } @@ -268,7 +288,7 @@ sdkVersion, ok := sm["version"] if ok { //鏈夌増鏈彿 vStr := sdkVersion.(string) - if shouldVersionBeUpgrade(vStr, skd.Def.Version) { + if shouldVersionBeUpgrade(vStr, skd.Def.Version) { //姣斿鐗堟湰鍙风‘瀹氭槸鍚﹂渶瑕佸畨瑁� nInsM[skd.Def.SdkType] = skd.Def.SdkType aInsM[skd.Def.Id] = skd.Def.Id } -- Gitblit v1.8.0