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 ++++++++++++++++++++++++++++-------- 1 files changed, 28 insertions(+), 8 deletions(-) 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