Browse Source

处理压缩包中的路径为相对路径

master ver2.0.2
xyiege 2 months ago
parent
commit
014b9aa555
  1. 3
      aufs/core/AuFile.go
  2. 5
      scagent/util/fsutil.go

3
aufs/core/AuFile.go

@ -53,9 +53,10 @@ func Flist(w http.ResponseWriter, r *http.Request) {
// 拼装路径,并转位unix路径
newpath := filepath.ToSlash(filepath.Join(basepath, wdir))
// basepath = fmt.Sprintf("%v%v", basepath, wdir)
// 调用远程方法
var reply string
var args = Args{newpath, "dir"}
var args = Args{FilePath: newpath, Scope: "dir"}
// var args = Args{"/www/wwwroot/fsc.com", "dir"}
err = client.Call("FileRpcService.GetFilePath", args, &reply)
// 执行完成后退出

5
scagent/util/fsutil.go

@ -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
}

Loading…
Cancel
Save