From 1afa5b031e2f13a2b93adc99d292cdeb2ba2a6dd Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期二, 11 二月 2020 18:30:55 +0800
Subject: [PATCH] add clearData
---
service/SysService.go | 59 +++++++++++++++++++++++++++--------------------------------
1 files changed, 27 insertions(+), 32 deletions(-)
diff --git a/service/SysService.go b/service/SysService.go
index 92957eb..1a1f14c 100644
--- a/service/SysService.go
+++ b/service/SysService.go
@@ -9,6 +9,7 @@
"mime/multipart"
"os"
"os/exec"
+ "path"
"strings"
"webserver/extend/config"
"webserver/extend/util"
@@ -95,11 +96,9 @@
if !util.CreateDirectory(configPatchPath) {
return false
}
- index := strings.LastIndex(arg.Header.Filename, ".")
- if index < 0 {
- return false
- }
- subfix := arg.Header.Filename[index:]
+
+ filenameWithSuffix := path.Base(arg.Header.Filename)
+ subfix := path.Ext(filenameWithSuffix)
MD5Str := arg.Identifier
logger.Debug("Identifier:",MD5Str)
fileTmpPath := configPatchPath + "/"+MD5Str
@@ -130,13 +129,14 @@
logger.Debug("read chunkData err:",err,"n:",n)
return false
}
- logger.Debug("read currentChunkData len:",n,"header data len:",arg.Header.Size,"data:",string(chunkData))
nn, err2 := writer.Write(chunkData)
if nn ==0 || err2 !=nil {
logger.Debug("write chunkData err:",err2,"nn:",nn)
return false
}
- logger.Debug("write chunkData len:",nn)
+ if err = writer.Flush(); err != nil {
+ logger.Debug("write flush err:",err)
+ }
isComplete := false
dirFiles, _ := ioutil.ReadDir(fileTmpPath)
if dirFiles != nil && len(dirFiles) == arg.TotalChunks {
@@ -163,11 +163,10 @@
} else {
configPatchPath = "/opt/vasystem/patch"
}
- index := strings.LastIndex(filename, ".")
- if index < 0 {
- return false,errors.New("闈炴硶鐨勫崌绾у帇缂╁寘鏂囦欢")
- }
- ext := filename[index:]
+
+ filenameWithSuffix := path.Base(filename)
+ ext := path.Ext(filenameWithSuffix)
+
zipFilePath := configPatchPath + "/"+identifier+ext
if util.Exists(zipFilePath) {
//鏍¢獙md5
@@ -176,15 +175,11 @@
return false,errors.New("鑾峰彇鍗囩骇鍘嬬缉鍖卪d5澶辫触")
}
if strMd5 == identifier {
- if util.ZipCheck(zipFilePath) {
- if !updatePatch(identifier, ext) {
- return false,errors.New("鎵ц鍗囩骇杩囩▼寮傚父")
- }
- return true,nil
- } else {
- logger.Debug("not a valid zip file,path:",zipFilePath)
- return false,errors.New("鍗囩骇绋嬪簭瑙e帇澶辫触锛岃纭畾涓婁紶鐨勮ˉ涓佹槸zip鏍煎紡")
+ if !updatePatch(identifier, ext) {
+ return false,errors.New("鎵ц鍗囩骇杩囩▼寮傚父,璇风‘瀹氫笂浼犵殑琛ヤ竵鏄痶ar.gz鏍煎紡")
}
+ return true,nil
+
} else {
logger.Debug("strMd5 is", strMd5,"identifier is",identifier,"not equal")
return false,errors.New("鏍¢獙鍗囩骇鏂囦欢澶辫触")
@@ -227,28 +222,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)
+ unPackFilePath := configPatchPath+"/"+identifier+ext
+ err := util.UnTarGz(unPackFilePath, unPackPath)
if err !=nil {
- logger.Debug("UnZip err:",err,"zipFile:",zipFilePath)
+ logger.Debug("UnPack err:",err,"unPackFile:",unPackFilePath)
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))
@@ -257,9 +252,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,unPackFilePath,configPatchPath+"/"+identifier)
+ if util.Exists(unPackPath+"upgrade.sh") {
+ updateCmd = fmt.Sprintf("%supgrade.sh %s %s %s &",unPackPath,unPackPath,unPackFilePath,configPatchPath+"/"+identifier)
}
//2.鏇存柊绯荤粺
b,err := ExecCmd(updateCmd)
--
Gitblit v1.8.0