|
|
|
@ -310,7 +310,8 @@ func DecompressZip(zpFname string) error { |
|
|
|
|
|
|
|
// dest:目的地址以及压缩文件名 eg:/data/logZip/2022-12-12-log.zip
|
|
|
|
// paths:需要压缩的所有文件所组成的集合
|
|
|
|
func CompressToZip(dest string, currentPath string, paths []string) error { |
|
|
|
func CompressToZip(dest string, currentPath string, basepath string, paths []string) error { |
|
|
|
// fmt.Printf("paths len:%d\n", len(paths))
|
|
|
|
// fmt.Println("real path", currentPath)
|
|
|
|
// 打开files 目录
|
|
|
|
filesPath := "" |
|
|
|
@ -336,7 +337,8 @@ func CompressToZip(dest string, currentPath string, paths []string) error { |
|
|
|
// 从配置中读取到源目录
|
|
|
|
src = path.Join(currentPath, "/", src) |
|
|
|
// 删除尾随路径(如果它是目录)
|
|
|
|
src := strings.TrimSuffix(src, string(os.PathSeparator)) |
|
|
|
src = strings.TrimSuffix(src, string(os.PathSeparator)) |
|
|
|
// fmt.Printf("zip src:%s\n", src)
|
|
|
|
// 文件遍历
|
|
|
|
err = filepath.Walk(src, func(path string, info os.FileInfo, err error) error { |
|
|
|
if err != nil { |
|
|
|
@ -350,7 +352,7 @@ func CompressToZip(dest string, currentPath string, paths []string) error { |
|
|
|
|
|
|
|
// 监听的工作目录作为文件的结尾,然后取相对路径
|
|
|
|
// 在zip存档中设置文件的相对路径
|
|
|
|
header.Name, err = filepath.Rel(filepath.Dir(config.G.FilePath), path) |
|
|
|
header.Name, err = filepath.Rel(filepath.Dir(basepath), path) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|