From fc91703f3cbee4dac9e56c3da694fccb386f4ce3 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期三, 29 七月 2020 19:30:54 +0800
Subject: [PATCH] add showInstallInfo

---
 service/SdkInstall.go |  107 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 91 insertions(+), 16 deletions(-)

diff --git a/service/SdkInstall.go b/service/SdkInstall.go
index edd704b..3c19e59 100644
--- a/service/SdkInstall.go
+++ b/service/SdkInstall.go
@@ -105,6 +105,87 @@
 	}
 }
 
+//瑙e帇涓婁紶鐨勭畻娉曞畨瑁呭寘
+func unPackPatchPackage(identifier string, ext string) (bool,error) {
+	configPatchPath := ""
+	if config.Server.PatchPath != "" {
+		configPatchPath = config.Server.PatchPath
+	} else {
+		configPatchPath = "../patch"
+	}
+	//1.瑙e帇缂╂洿鏂板寘
+	unPackTargetPath := configPatchPath+"/"+identifier+"_basic/"
+	unPackFilePath := configPatchPath+"/"+identifier+ext
+
+	if util.Exists(unPackTargetPath) {
+		//姝ょ増鏈凡缁忔洿鏂拌繃
+		rmErr := os.RemoveAll(unPackTargetPath)
+		if rmErr !=nil {
+			return false,rmErr
+		}
+	}
+	if !util.CreateDirectory(unPackTargetPath) {
+		return false, errors.New("鍒涘缓鍘嬬缉鏂囦欢澶瑰け璐�")
+	}
+	logger.Debug("unPackFilePath:", unPackFilePath, "unPackPath:", unPackTargetPath)
+	_,err := util.UnTarGzByCmd(unPackFilePath, unPackTargetPath)
+	if err !=nil {
+		logger.Debug("UnPack err:",err,"unPackFile:",unPackFilePath)
+		return false, err
+	}
+	return true, nil
+}
+
+func (sv SdkInstallService) ShowInstallInfo(identifier string) (bool, map[string]interface{}) {
+	configPatchPath := ""
+	if config.Server.PatchPath != "" {
+		configPatchPath = config.Server.PatchPath
+	} else {
+		configPatchPath = "../patch"
+	}
+	unPackTargetPath := configPatchPath+"/"+identifier+"_basic/"
+	if util.Exists(unPackTargetPath) {
+		targetFileName := ""
+		err := filepath.Walk(unPackTargetPath, func(path string, f os.FileInfo, err error) error {
+			if f == nil {
+				return err
+			}
+			if f.IsDir() {
+				targetFileName = f.Name()
+			}
+			return nil
+		})
+		if err != nil {
+			return false, nil
+		} else {
+			unPackPath := unPackTargetPath + targetFileName +"/"
+			//瑙e帇瀹屾垚锛岃幏鍙栧畨瑁呭寘涓殑鏂囦欢锛屽紑濮嬪畨瑁�
+			//1.瑙f瀽瀹夎璇存槑ins.inc
+			incPath := unPackPath+"ins.inc"
+			if util.Exists(incPath) {
+				if incB, err := ioutil.ReadFile(incPath); err == nil {
+					var ins InsInc
+					if err = json.Unmarshal(incB, &ins); err == nil {
+						return true, map[string]interface{} {
+							"sdkName": ins.ProductName,
+							"installVersion": ins.InstallVersion,
+							"installContent": ins.InstallContent,
+						}
+					} else {
+						return false, nil
+					}
+				} else {
+					return false, nil
+				}
+			} else {
+				return false, nil
+			}
+		}
+	} else {
+		return false, nil
+	}
+}
+
 //瀹夎sdk
 func installSdk(identifier string, ext string) (bool, error) {
 	configPatchPath := ""
@@ -129,25 +210,12 @@
 		}
 	}()
 
-	if util.Exists(unPackTargetPath) {
-		//姝ょ増鏈凡缁忔洿鏂拌繃
-		rmErr := os.RemoveAll(unPackTargetPath)
-		if rmErr !=nil {
-			return false,rmErr
-		}
-	}
-	if !util.CreateDirectory(unPackTargetPath) {
-		return false, errors.New("鍒涘缓鍘嬬缉鏂囦欢澶瑰け璐�")
+	if !util.Exists(unPackTargetPath) {//瀹夎鍖呬笉瀛樺湪
+		return false, errors.New("瀹夎鏂囦欢宸蹭笉瀛樺湪")
 	}
 
-	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(unPackTargetPath, 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
 		}
@@ -160,6 +228,9 @@
 		return false, err
 	}
 	unPackPath := unPackTargetPath + targetFileName +"/"
+	if !util.Exists(unPackPath) {
+		return false, errors.New("瀹夎鏂囦欢宸蹭笉瀛樺湪")
+	}
 	//瑙e帇瀹屾垚锛岃幏鍙栧畨瑁呭寘涓殑鏂囦欢锛屽紑濮嬪畨瑁�
 	//1.瑙f瀽瀹夎璇存槑ins.inc
 	incPath := unPackPath+"ins.inc"
@@ -362,6 +433,10 @@
 	ChCount 			int 		`json:"chCount"`
 	AuthCount 			int 		`json:"authCount"`
 	ServeYear			int 		`json:"serveYear"`
+
+	ProductName 		string 		`json:"productName"`
+	InstallVersion 		string 		`json:"installVersion"`
+	InstallContent 		string 		`json:"installContent"`
 }
 
 //绠楁硶鍜屽弬鏁板畾涔�

--
Gitblit v1.8.0