liuxiaolong
2020-06-04 0d858e8610a79b15cb337daf134c4a00962dd477
service/SdkInstall.go
@@ -2,7 +2,6 @@
import (
   "basic.com/dbapi.git"
   //"basic.com/dbapi.git"
   "basic.com/valib/logger.git"
   "encoding/json"
   "errors"
@@ -14,8 +13,12 @@
   "webserver/extend/util"
)
type SdkInstallService struct {
}
//算法安装包安装
func (sv SysService) SdkInstall(identifier string,filename string) (bool,error) {
func (sv SdkInstallService) SdkInstall(identifier string,filename string) (bool,error) {
   configPatchPath := ""
   if config.Server.PatchPath != "" {
      configPatchPath = config.Server.PatchPath
@@ -30,6 +33,7 @@
   if util.Exists(zipFilePath) {
      strMd5, e := util.FileMd5(zipFilePath)
      if e !=nil || strMd5 == "" {
         go os.Remove(zipFilePath)
         return false,errors.New("获取安装包md5失败")
      }
      if strMd5 == identifier {
@@ -39,6 +43,7 @@
         return true,nil
      } else {
         go os.Remove(zipFilePath)
         logger.Debug("strMd5 is", strMd5,"identifier is",identifier,"not equal")
         return false,errors.New("校验安装文件失败")
      }
@@ -56,27 +61,36 @@
      configPatchPath = "/opt/vasystem/patch"
   }
   //1.解压缩更新包
   unPackPath := configPatchPath+"/"+identifier+"_basic/"
   if util.Exists(unPackPath) {
   unPackTargetPath := configPatchPath+"/"+identifier+"_basic/"
   unPackFilePath := configPatchPath+"/"+identifier+ext
   defer func() {
      if util.Exists(unPackTargetPath) {
         os.RemoveAll(unPackTargetPath)
      }
      if util.Exists(unPackFilePath) {
         os.RemoveAll(unPackFilePath)
      }
   }()
   if util.Exists(unPackTargetPath) {
      //此版本已经更新过
      rmErr := os.RemoveAll(unPackPath)
      rmErr := os.RemoveAll(unPackTargetPath)
      if rmErr !=nil {
         return false,rmErr
      }
   }
   if !util.CreateDirectory(unPackPath) {
   if !util.CreateDirectory(unPackTargetPath) {
      return false, errors.New("创建压缩文件夹失败")
   }
   unPackFilePath := configPatchPath+"/"+identifier+ext
   logger.Debug("unPackFilePath:", unPackFilePath, "unPackPath:", unPackPath)
   _,err := util.UnTarGzByCmd(unPackFilePath, unPackPath)
   logger.Debug("unPackFilePath:", unPackFilePath, "unPackPath:", unPackTargetPath)
   _,err := util.UnTarGzByCmd(unPackFilePath, unPackTargetPath)
   if err !=nil {
      logger.Debug("UnPack err:",err,"unPackFile:",unPackFilePath)
      return false, err
   }
   targetFileName := ""
   err = filepath.Walk(unPackPath, func(path string, f os.FileInfo, err error) error {
   err = filepath.Walk(unPackTargetPath, func(path string, f os.FileInfo, err error) error {
      if f == nil {
         return err
      }
@@ -88,7 +102,7 @@
   if err != nil {
      return false, err
   }
   unPackPath = unPackPath + targetFileName +"/"
   unPackPath := unPackTargetPath + targetFileName +"/"
   //解压完成,获取安装包中的文件,开始安装
   //1.解析安装说明ins.inc
   incPath := unPackPath+"ins.inc"