From c84d13cdcab4472a9e8b7a18e275050d296ad100 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期六, 30 五月 2020 14:38:44 +0800
Subject: [PATCH] fix SdkInstall
---
extend/util/zip.go | 6 +++
service/SdkInstall.go | 73 +++++++++++++++++++++++-------------
2 files changed, 53 insertions(+), 26 deletions(-)
diff --git a/extend/util/zip.go b/extend/util/zip.go
index f057359..6a54c20 100644
--- a/extend/util/zip.go
+++ b/extend/util/zip.go
@@ -10,6 +10,7 @@
"io/ioutil"
"log"
"os"
+ "os/exec"
"path"
"path/filepath"
"strings"
@@ -316,6 +317,11 @@
return (err == nil || os.IsExist(err)) && fi.IsDir()
}
+func CopyDirByCmd(src ,dest string) (string,error) {
+ cmd := exec.Command("cp","-r", src, dest)
+ outPut, err := cmd.Output()
+ return string(outPut), err
+}
//鏂囦欢澶瑰鍒�
func CopyDir(src string, dest string) {
diff --git a/service/SdkInstall.go b/service/SdkInstall.go
index 9153ffc..31088e4 100644
--- a/service/SdkInstall.go
+++ b/service/SdkInstall.go
@@ -31,8 +31,8 @@
return false,errors.New("鑾峰彇瀹夎鍖卪d5澶辫触")
}
if strMd5 == identifier {
- if !installSdk(identifier, ext) {
- return false,errors.New("鎵ц瀹夎杩囩▼寮傚父,璇风‘瀹氫笂浼犵殑瀹夎鍖呮槸tar.gz鏍煎紡")
+ if _,insE := installSdk(identifier, ext); insE != nil {
+ return false, insE
}
return true,nil
@@ -46,7 +46,7 @@
}
//瀹夎sdk
-func installSdk(identifier string, ext string) bool {
+func installSdk(identifier string, ext string) (bool, error) {
configPatchPath := ""
if config.Server.PatchPath != "" {
configPatchPath = config.Server.PatchPath
@@ -59,23 +59,22 @@
//姝ょ増鏈凡缁忔洿鏂拌繃
rmErr := os.RemoveAll(unPackPath)
if rmErr !=nil {
- return false
+ return false,rmErr
}
}
if !util.CreateDirectory(unPackPath) {
- return false
+ return false, errors.New("鍒涘缓鍘嬬缉鏂囦欢澶瑰け璐�")
}
unPackFilePath := configPatchPath+"/"+identifier+ext
err := util.UnTarGz(unPackFilePath, unPackPath)
if err !=nil {
logger.Debug("UnPack err:",err,"unPackFile:",unPackFilePath)
- return false
+ return false, err
}
//瑙e帇瀹屾垚锛岃幏鍙栧畨瑁呭寘涓殑鏂囦欢锛屽紑濮嬪畨瑁�
//1.瑙f瀽瀹夎璇存槑ins.inc
incPath := unPackPath+"ins.inc"
- ret := false
if util.Exists(incPath) {
if incB, err := ioutil.ReadFile(incPath);err == nil {
var ins InsInc
@@ -90,6 +89,34 @@
soM := make(map[string]SdkDef)
var skDefArr []SdkDef
if err = json.Unmarshal(defB, &skDefArr);err == nil {
+ zconfPath := "/opt/vasystem/bin/zconf/"
+ libPath := "/opt/vasystem/libs/"
+ if !util.DirExists(zconfPath) {
+ os.MkdirAll(zconfPath, 0777)
+ }
+ if !util.DirExists(libPath) {
+ os.MkdirAll(libPath, 0777)
+ }
+ for sdkType,_ := range soM {
+ //鍏堣В鍘婼dkType.tar.gz鏂囦欢
+ if unTarGzE := util.UnTarGz(unPackPath+sdkType+".tar.gz", unPackPath);unTarGzE == nil {
+ //澶嶅埗json鍚姩鏂囦欢
+ if util.Exists(unPackPath+sdkType+"/zconf/"+sdkType+".json") {
+ util.CopyFile(unPackPath+sdkType+"/zconf/"+sdkType+".json", zconfPath)
+ }
+ if util.DirExists(unPackPath+sdkType+"/"+sdkType) {
+ if _,cE := util.CopyDirByCmd(unPackPath+sdkType+"/"+sdkType, libPath);cE != nil {
+ return false, cE
+ }
+ }
+ if util.DirExists(unPackPath+sdkType+"/models") {
+ if _,cE := util.CopyDirByCmd(unPackPath+sdkType+"/models", "/opt/vasystem/bin/"); cE != nil {
+ return false, cE
+ }
+ }
+ }
+ }
+ //娉ㄥ唽绠楁硶淇℃伅鍜岀畻娉曞弬鏁板埌dbserver
var sdkApi dbapi.SdkApi
for _,skd := range skDefArr {
if _,ok := soM[skd.Def.SdkType];!ok {
@@ -123,32 +150,26 @@
paramBody := util.Struct2Map(srv)
sdkApi.Register(paramBody) //灏嗙畻娉曟敞鍐屽埌鏁版嵁搴撲腑
}
-
- zconfPath := "/opt/vasystem/bin/zconf/"
- libPath := "/opt/vasystem/libs/"
- if !util.DirExists(zconfPath) {
- os.MkdirAll(zconfPath, 0777)
- }
- if !util.DirExists(libPath) {
- os.MkdirAll(libPath, 0777)
- }
- for sdkType,_ := range soM {
- //澶嶅埗json鍚姩鏂囦欢
- util.CopyFile(unPackPath+sdkType+"/zconf/"+sdkType+".json", zconfPath)
- util.CopyDir(unPackPath+sdkType+"/"+sdkType, libPath)
- if util.DirExists(unPackPath+sdkType+"/models") {
- util.CopyDir(unPackPath+sdkType+"/models", "/opt/vasystem/bin/")
- }
- }
- ret = true
+ } else {
+ return false, errors.New("鍙嶅簭鍒楀寲绠楁硶瀹氫箟淇℃伅澶辫触")
}
+ } else {
+ return false, errors.New("璇诲彇绠楁硶瀹氫箟淇℃伅澶辫触")
}
+ } else {
+ return false, errors.New("绠楁硶瀹氫箟淇℃伅涓㈠け")
}
+ } else {
+ return false, errors.New("鍙嶅簭鍒楀寲鎺堟潈淇℃伅澶辫触")
}
+ } else {
+ return false, errors.New("璇诲彇鎺堟潈鏂囦欢澶辫触")
}
+ } else {
+ return false, errors.New("鎺堟潈鏂囦欢涓嶅瓨鍦�")
}
- return ret
+ return true, nil
}
--
Gitblit v1.8.0