LingxinMeng 9 mēneši atpakaļ
vecāks
revīzija
c8db6084da

+ 3 - 3
aarch64/pjibot_guide/common/config/c_cloud.go

@@ -60,9 +60,9 @@ type CollectLimitStruct struct {
 }
 
 type DataDirStruct struct {
-	Src     string   `yaml:"src"`
-	Dest    string   `yaml:"dest"`
-	Exclude []string `yaml:"exclude"`
+	Src    string   `yaml:"src"`
+	SrcSub []string `yaml:"src-sub"`
+	Dest   string   `yaml:"dest"`
 }
 
 type cloudConfig struct {

+ 2 - 2
aarch64/pjibot_guide/common/service/rosbag_upload.go

@@ -158,11 +158,11 @@ outLoop:
 
 		// 压缩采集data目录
 		{
-			err = util.ZipDir(commonConfig.CloudConfig.DataDir.Src, commonConfig.CloudConfig.DataDir.Dest, commonConfig.CloudConfig.DataDir.Exclude)
+			err = util.ZipDir(commonConfig.CloudConfig.DataDir.Src, commonConfig.CloudConfig.DataDir.Dest, commonConfig.CloudConfig.DataDir.SrcSub)
 			if err != nil {
 				c_log.GlobalLogger.Error("压缩data目录失败:", err)
 			} else {
-				c_log.GlobalLogger.Infof("压缩data目录【%v】->【%v】成功,并排除了目录【%v】", commonConfig.CloudConfig.DataDir.Src, commonConfig.CloudConfig.DataDir.Dest, commonConfig.CloudConfig.DataDir.Exclude)
+				c_log.GlobalLogger.Infof("压缩data目录【%v】->【%v】成功", commonConfig.CloudConfig.DataDir.Src, commonConfig.CloudConfig.DataDir.Dest)
 			}
 			dataZipKey := objectKey3 + "data.zip"
 			err = commonConfig.OssBucket.PutObjectFromFile(dataZipKey, commonConfig.CloudConfig.DataDir.Dest)

+ 4 - 7
aarch64/pjibot_guide/引导机器人默认配置文件-cloud-config.yaml

@@ -18,14 +18,11 @@ disk:
   used: 20000000000 # 磁盘占用阈值,单位bytes
 data-dir:
   src: /root/pjirobot/data/ # 需要额外采集的 data 目录
+  src-sub:
+    - config
+    - map
+    - mapBuf
   dest: /root/pjirobot/data.zip
-  exclude: # 采集data目录时排除的子目录
-    - /root/pjirobot/data/bags/
-    - /root/pjirobot/data/bufTest/
-    - /root/pjirobot/data/cicv-data-closedloop/
-    - /root/pjirobot/data/external_device/
-    - /root/pjirobot/data/init_map_files/
-    - /root/pjirobot/data/logs/
 map-buf-files:
   - /root/pjirobot/data/mapBuf/forbid_area.json
   - /root/pjirobot/data/mapBuf/forbid_area.yaml

+ 14 - 26
common/util/u_io.go

@@ -1,7 +1,6 @@
 package util
 
 import (
-	"bytes"
 	"fmt"
 	"io"
 	"io/fs"
@@ -12,38 +11,27 @@ import (
 	"strings"
 )
 
-// 压缩指定目录到ZIP文件,并排除一个指定的子目录
-func ZipDir(src, dest string, excludeDirs []string) error {
-	// 构造排除参数的字符串
-	excludeArgs := make([]string, 0, len(excludeDirs))
-	for _, excludeDir := range excludeDirs {
-		relExcludeDir, err := filepath.Rel(src, excludeDir)
-		if err != nil {
-			return err
-		}
-		// 确保排除路径以 '*' 结尾,以匹配目录下的所有内容
-		excludeArgs = append(excludeArgs, filepath.Join(relExcludeDir, "*"))
+// 将指定的目录和子目录压缩成 ZIP 文件
+func ZipDir(src string, dest string, dirs []string) error {
+	// 创建 zip 命令参数
+	args := []string{"-r", dest}
+	for _, dir := range dirs {
+		args = append(args, filepath.Join(src, dir))
 	}
 
-	// 拼接 -x 参数
-	excludeStr := strings.Join(excludeArgs, " -x ")
+	// 创建 zip 命令
+	cmd := exec.Command("zip", args...)
 
-	// 构建zip命令
-	cmd := exec.Command("zip", append([]string{"-r", dest, "."}, strings.Split(excludeStr, " ")...)...)
-
-	// 设置工作目录为要压缩的源目录
+	// 设置工作目录
 	cmd.Dir = src
 
-	// 捕获命令的标准输出和标准错误输出
-	var out bytes.Buffer
-	cmd.Stdout = &out
-	cmd.Stderr = &out
-
-	// 运行命令
-	if err := cmd.Run(); err != nil {
-		return fmt.Errorf("zip command failed: %v, output: %s", err, out.String())
+	// 执行 zip 命令并获取输出
+	output, err := cmd.CombinedOutput()
+	if err != nil {
+		return fmt.Errorf("error while executing zip command: %v\nOutput: %s", err, output)
 	}
 
+	fmt.Printf("ZIP file created successfully: %s\n", dest)
 	return nil
 }