|
|
|
@ -311,6 +311,7 @@ func DecompressZip(zpFname string) error { |
|
|
|
// dest:目的地址以及压缩文件名 eg:/data/logZip/2022-12-12-log.zip
|
|
|
|
// paths:需要压缩的所有文件所组成的集合
|
|
|
|
func CompressToZip(dest string, currentPath string, paths []string) error { |
|
|
|
// fmt.Printf("currentPath:%s\n", currentPath)
|
|
|
|
// fmt.Printf("paths len:%d\n", len(paths))
|
|
|
|
// fmt.Println("real path", currentPath)
|
|
|
|
// 打开files 目录
|
|
|
|
@ -341,6 +342,7 @@ func CompressToZip(dest string, currentPath string, paths []string) error { |
|
|
|
// fmt.Printf("zip src:%s\n", src)
|
|
|
|
// 文件遍历
|
|
|
|
err = filepath.Walk(src, func(path string, info os.FileInfo, err error) error { |
|
|
|
// fmt.Printf("zip path:%s\n", path)
|
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
@ -352,7 +354,8 @@ 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(src), path) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|