liuxiaolong
2020-07-29 07642fd86de34583052d9467260ec6c30e7ded9e
verify invalid install pack
2个文件已修改
42 ■■■■ 已修改文件
controllers/sdk.go 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/SdkInstall.go 38 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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 {
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 +"/"
            //解压完成,获取安装包中的文件,开始安装
@@ -170,19 +190,19 @@
                            "sdkName": ins.ProductName,
                            "installVersion": ins.InstallVersion,
                            "installContent": ins.InstallContent,
                        }, nil
                    } else {
                        return false, nil, errors.New("非法的安装包")
                        }
                    } else {
                        return false, nil
                    return false, nil, errors.New("非法的安装包")
                    }
                } else {
                    return false, nil
                }
            } 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
                                        }