浏览代码

fix(plugin): install plugins with shellParas, plugin zip package must have install.sh file

Signed-off-by: Jianxiang Ran <rxan_embedded@163.com>
Jianxiang Ran 3 年之前
父节点
当前提交
d44c355a13
共有 1 个文件被更改,包括 12 次插入5 次删除
  1. 12 5
      internal/plugin/native/manager.go

+ 12 - 5
internal/plugin/native/manager.go

@@ -410,6 +410,17 @@ func (rr *Manager) install(t plugin2.PluginType, name, src string, shellParas []
 	}
 	}
 	defer r.Close()
 	defer r.Close()
 
 
+	haveInstallFile := false
+	for _, file := range r.File {
+		fileName := file.Name
+		if fileName == "install.sh" {
+			haveInstallFile = true
+		}
+	}
+	if len(shellParas) != 0 && !haveInstallFile {
+		return filenames, "", fmt.Errorf("have shell parameters : %s but no install.sh file", shellParas)
+	}
+
 	soPrefix := regexp.MustCompile(fmt.Sprintf(`^((%s)|(%s))(@.*)?\.so$`, name, ucFirst(name)))
 	soPrefix := regexp.MustCompile(fmt.Sprintf(`^((%s)|(%s))(@.*)?\.so$`, name, ucFirst(name)))
 	var yamlFile, yamlPath, version string
 	var yamlFile, yamlPath, version string
 	expFiles := 1
 	expFiles := 1
@@ -419,7 +430,6 @@ func (rr *Manager) install(t plugin2.PluginType, name, src string, shellParas []
 		expFiles = 2
 		expFiles = 2
 	}
 	}
 	var revokeFiles []string
 	var revokeFiles []string
-	needInstall := false
 	for _, file := range r.File {
 	for _, file := range r.File {
 		fileName := file.Name
 		fileName := file.Name
 		if yamlFile == fileName {
 		if yamlFile == fileName {
@@ -455,14 +465,11 @@ func (rr *Manager) install(t plugin2.PluginType, name, src string, shellParas []
 			if err != nil {
 			if err != nil {
 				return filenames, "", err
 				return filenames, "", err
 			}
 			}
-			if fileName == "install.sh" {
-				needInstall = true
-			}
 		}
 		}
 	}
 	}
 	if len(filenames) != expFiles {
 	if len(filenames) != expFiles {
 		return filenames, version, fmt.Errorf("invalid zip file: so file or conf file is missing")
 		return filenames, version, fmt.Errorf("invalid zip file: so file or conf file is missing")
-	} else if needInstall {
+	} else if haveInstallFile {
 		//run install script if there is
 		//run install script if there is
 		spath := path.Join(tempPath, "install.sh")
 		spath := path.Join(tempPath, "install.sh")
 		shellParas = append(shellParas, spath)
 		shellParas = append(shellParas, spath)