liuxiaolong
2019-12-19 94bcda3ef533ac0ab0f5c0786554a9efe4c27f4d
service/SysService.go
@@ -3,6 +3,7 @@
import (
   "basic.com/valib/logger.git"
   "bufio"
   "errors"
   "fmt"
   "io/ioutil"
   "mime/multipart"
@@ -75,12 +76,8 @@
      dirFiles, _ := ioutil.ReadDir(fileTmpPath)
      if dirFiles != nil && len(dirFiles) == arg.TotalChunks {
         //表示所有分块都上传了,需要merge
         if sv.MergeChunks(fileTmpPath, mergedFilePath) {
            if util.ZipCheck(mergedFilePath) {
               if !updatePatch(arg.Identifier, subfix) {
                  return false
               }
            }
         if !sv.MergeChunks(fileTmpPath, mergedFilePath) {
            return false
         }
      }
   }
@@ -146,18 +143,52 @@
   if isComplete {
      if sv.MergeChunks(fileTmpPath,fileTmpPath + subfix) {
         logger.Debug("merge all chunks success,identifier:",MD5Str,"fileName:",arg.FileName)
         if util.ZipCheck(fileTmpPath + subfix) {
            if !updatePatch(arg.Identifier, subfix) {
               return false
            }
         } else {
            logger.Debug("not a valid zip file,path:",fileTmpPath+subfix)
         }
      } else {
         return false
      }
   }
   return true
}
//upgrade
func (sv SysService) Upgrade(identifier string,filename string) (bool,error) {
   configPatchPath := ""
   if config.Server.PatchPath != "" {
      configPatchPath = config.Server.PatchPath
   } else {
      configPatchPath = "/opt/vasystem/patch"
   }
   index := strings.LastIndex(filename, ".")
   if index < 0 {
      return false,errors.New("非法的升级压缩包文件")
   }
   ext := filename[index:]
   zipFilePath := configPatchPath + "/"+identifier+ext
   if util.Exists(zipFilePath) {
      //校验md5
      strMd5, e := util.FileMd5(zipFilePath)
      if e !=nil || strMd5 == "" {
         return false,errors.New("获取升级压缩包md5失败")
      }
      if strMd5 == identifier {
         if util.ZipCheck(zipFilePath + ext) {
            if !updatePatch(identifier, ext) {
               return false,errors.New("执行升级过程异常")
            }
            return true,nil
         } else {
            logger.Debug("not a valid zip file,path:",zipFilePath+ext)
            return false,errors.New("升级程序解压失败,请确定上传的补丁是zip格式")
         }
      } else {
         logger.Debug("strMd5 is", strMd5,"identifier is",identifier,"not equal")
         return false,errors.New("校验升级文件失败")
      }
   } else {
      return false,errors.New("升级文件已丢失,请重新上传")
   }
}
//更新系统程序
func updatePatch(identifier string, ext string) bool {
   configPatchPath := ""