From 17bd0564775dd89a9e7f9dafb44624b05866714d Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期五, 20 十二月 2019 18:31:36 +0800
Subject: [PATCH] upgrade use tar.gz

---
 service/SysService.go |   27 +++++++++++++++------------
 1 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/service/SysService.go b/service/SysService.go
index 4b14658..02f67b5 100644
--- a/service/SysService.go
+++ b/service/SysService.go
@@ -124,7 +124,7 @@
 	}
 	defer file.Close()
 	writer := bufio.NewWriter(file)
-	chunkData := make([]byte, arg.CurrentChunkSize)
+	chunkData := make([]byte, arg.Header.Size)
 	n, err := (*arg.File).ReadAt(chunkData, 0)
 	if n ==0 || err !=nil {
 		logger.Debug("read chunkData err:",err,"n:",n)
@@ -134,6 +134,9 @@
 	if nn ==0 || err2 !=nil {
 		logger.Debug("write chunkData err:",err2,"nn:",nn)
 		return false
+	}
+	if err = writer.Flush(); err != nil {
+		logger.Debug("write flush err:",err)
 	}
 	isComplete := false
 	dirFiles, _ := ioutil.ReadDir(fileTmpPath)
@@ -174,7 +177,7 @@
 			return false,errors.New("鑾峰彇鍗囩骇鍘嬬缉鍖卪d5澶辫触")
 		}
 		if strMd5 == identifier {
-			if util.ZipCheck(zipFilePath) {
+			if util.TarGzCheck(zipFilePath) {
 				if !updatePatch(identifier, ext) {
 					return false,errors.New("鎵ц鍗囩骇杩囩▼寮傚父")
 				}
@@ -225,28 +228,28 @@
 		configPatchPath = "/opt/vasystem/patch"
 	}
 	//1.瑙e帇缂╂洿鏂板寘
-	unZipPath := configPatchPath+"/"+identifier+"_basic/"
-	if util.Exists(unZipPath) {
+	unPackPath := configPatchPath+"/"+identifier+"_basic/"
+	if util.Exists(unPackPath) {
 		//姝ょ増鏈凡缁忔洿鏂拌繃
-		rmErr := os.RemoveAll(unZipPath)
+		rmErr := os.RemoveAll(unPackPath)
 		if rmErr !=nil {
 			return false
 		}
 	}
-	if !util.CreateDirectory(unZipPath) {
+	if !util.CreateDirectory(unPackPath) {
 		return false
 	}
 
 	zipFilePath := configPatchPath+"/"+identifier+ext
-	err := util.UnZip(zipFilePath, unZipPath)
+	err := util.DeCompress(zipFilePath, unPackPath)
 	if err !=nil {
 		logger.Debug("UnZip err:",err,"zipFile:",zipFilePath)
 		return false
 	}
 
 	//濡傛灉閫氱敤鑴氭湰鏈夋洿鏂帮紝鍒欐洿鏂伴�氱敤鑴氭湰
-	if util.Exists(unZipPath+"updatePatch.sh") {
-		cpStr := fmt.Sprintf("cp %s /opt/vasystem/bin",unZipPath+"updatePatch.sh")
+	if util.Exists(unPackPath+"updatePatch.sh") {
+		cpStr := fmt.Sprintf("cp %s /opt/vasystem/bin",unPackPath+"updatePatch.sh")
 		b, err := ExecCmd(cpStr)
 		if err != nil {
 			logger.Debug("cp updatePatch.sh to bin err:",err,"result:",string(b))
@@ -255,9 +258,9 @@
 	}
 
 	//鍒ゆ柇鏇存柊鍖呴噷鏄惁鏈夎ˉ涓佽剼鏈紝濡傛灉鏈夊垯鎵ц锛屽惁鍒欐墽琛寀pdatePatch.sh
-	updateCmd := fmt.Sprintf("./updatePatch.sh %s %s %s &",unZipPath,zipFilePath,configPatchPath+"/"+identifier)
-	if util.Exists(unZipPath+"upgrade.sh") {
-		updateCmd = fmt.Sprintf("%supgrade.sh %s %s %s &",unZipPath,unZipPath,zipFilePath,configPatchPath+"/"+identifier)
+	updateCmd := fmt.Sprintf("./updatePatch.sh %s %s %s &",unPackPath,zipFilePath,configPatchPath+"/"+identifier)
+	if util.Exists(unPackPath+"upgrade.sh") {
+		updateCmd = fmt.Sprintf("%supgrade.sh %s %s %s",unPackPath,unPackPath,zipFilePath,configPatchPath+"/"+identifier)
 	}
 	//2.鏇存柊绯荤粺
 	b,err := ExecCmd(updateCmd)

--
Gitblit v1.8.0