LingxinMeng 10 hónapja
szülő
commit
55aa570987

+ 1 - 0
aarch64/pjisuv/common/config/yaml/通用-cloud-config.yaml

@@ -88,6 +88,7 @@ hosts:
       - /points_concat  # /lidar_pretreatment
       - /tpperception # /sensorfusion
       - /cicv_location  # /ins
+      - /pj_vehicle_fdb_pub
 triggers:
   - label: rapidaccel
     topics:

+ 13 - 7
aarch64/pjisuv/master/config/trigger_init.go

@@ -23,23 +23,29 @@ func InitTriggerConfig() {
 	localTriggerIds := util.GetFirstLevelSubdirectories(config.CloudConfig.TriggersDir)
 	// 3 对比触发器列表,本地没有的则下载
 	for _, trigger := range *cloudTriggers {
-		label := util.GetFileNameWithoutExtension(config.CloudConfig.TriggersDir + trigger.TriggerScriptPath)
 		id := util.ToString(trigger.TriggerId)
-		triggerLocalPath := config.CloudConfig.TriggersDir + label + "_" + id + "/" + label + ".so"
-		triggerLocalPaths = append(triggerLocalPaths, triggerLocalPath)
+		var triggerLocalPath string
+		triggerLocalDir := config.CloudConfig.TriggersDir + id + "/"
 		_ = util.CreateParentDir(triggerLocalPath)
-		contains, _ := util.ContainsElement(localTriggerIds, id)
-		if contains { // 已存在的触发器不需要再次下载
+		hasIdDir, _ := util.ContainsElement(localTriggerIds, id)
+		hasLabelSo, soPaths := util.CheckSoFilesInDirectory(triggerLocalDir)
+		if hasIdDir && hasLabelSo { // 已存在的触发器不需要再次下载
+			triggerLocalPath = soPaths[0]
+			c_log.GlobalLogger.Info("触发器插件从 ", triggerLocalPath, " 存在。")
+			triggerLocalPaths = append(triggerLocalPaths, triggerLocalPath)
 			continue
 		}
+		label := util.GetFileNameWithoutExtension(config.CloudConfig.TriggersDir + trigger.TriggerScriptPath)
+		triggerLocalPath = config.CloudConfig.TriggersDir + id + "/" + label + ".so"
+		c_log.GlobalLogger.Info("下载触发器插件从 ", trigger.TriggerScriptPath, " 到 ", triggerLocalPath)
 		config.OssMutex.Lock()
 		err := config.OssBucket.GetObjectToFile(trigger.TriggerScriptPath, triggerLocalPath)
 		config.OssMutex.Unlock()
 		if err != nil {
-			c_log.GlobalLogger.Error("下载 oss 上的触发器插件失败:", err)
+			c_log.GlobalLogger.Error("下载 OSS 上的触发器插件失败:", err)
 			continue
 		}
-		c_log.GlobalLogger.Info("下载触发器插件从 ", trigger.TriggerScriptPath, " 到 ", triggerLocalPath)
+		triggerLocalPaths = append(triggerLocalPaths, triggerLocalPath)
 	}
 
 	// 下载所有触发器的文件

+ 29 - 0
common/util/u_io.go

@@ -3,12 +3,41 @@ package util
 import (
 	"fmt"
 	"io"
+	"io/fs"
 	"os"
 	"path/filepath"
 	"sort"
 	"strings"
 )
 
+func CheckSoFilesInDirectory(dirPath string) (bool, []string) {
+	var hasSoFile bool
+	var soFilePaths []string
+
+	err := filepath.Walk(dirPath, func(path string, info fs.FileInfo, err error) error {
+		if err != nil {
+			return err
+		}
+
+		if info.IsDir() {
+			return nil
+		}
+
+		if filepath.Ext(path) == ".so" {
+			hasSoFile = true
+			soFilePaths = append(soFilePaths, path)
+		}
+		return nil
+	})
+
+	if err != nil {
+		fmt.Println("Error walking the directory:", err)
+		os.Exit(1)
+	}
+
+	return hasSoFile, soFilePaths
+}
+
 func GetFirstLevelSubdirectories(dirPath string) []string {
 	dirEntries, _ := os.ReadDir(dirPath)
 	subdirectories := make([]string, 0)