Compare commits

...

2 Commits

  1. 1
      scagent/core/UpFile.go
  2. 7
      scagent/util/fsutil.go
  3. 1
      scalib/main.go

1
scagent/core/UpFile.go

@ -90,6 +90,7 @@ func (f *UpFileService) UnzipArchive(info FileInfo, reply *string) error {
// 日志 // 日志
logger := util.NewProductionLogger() logger := util.NewProductionLogger()
defer logger.Sync() defer logger.Sync()
logger.Info("UnzipArchive", zap.String("filename", info.FileName))
// 解压缩文件 // 解压缩文件
ret := make(chan string) ret := make(chan string)
go func() { go func() {

7
scagent/util/fsutil.go

@ -266,8 +266,9 @@ func ZipFiles(zipname string, files []string, zippath string) error {
// 解压缩zip文件 // 解压缩zip文件
// 这个方法必须是首字母大写的,才能被注册 // 这个方法必须是首字母大写的,才能被注册
// src: 需要解压的zip文件 // zpFname: 需要解压的zip文件
func DecompressZip(zpFname string) error { // dirpath: 解压到的目录
func DecompressZip(zpFname string, dirpath string) error {
// 下载文件 // 下载文件
archive, err := zip.OpenReader(zpFname) archive, err := zip.OpenReader(zpFname)
if err != nil { if err != nil {
@ -279,7 +280,7 @@ func DecompressZip(zpFname string) error {
// 遍历目录 // 遍历目录
for _, f := range archive.File { for _, f := range archive.File {
// zip 解压的时候,路径为监听的路径 // zip 解压的时候,路径为监听的路径
filePath := filepath.Join(config.G.FilePath, f.Name) filePath := filepath.Join(dirpath, f.Name)
// 暂停原因 屏蔽解压到files 目录下 // 暂停原因 屏蔽解压到files 目录下
//filePath := filepath.Join(dir, f.Name) //filePath := filepath.Join(dir, f.Name)
if f.FileInfo().IsDir() { if f.FileInfo().IsDir() {

1
scalib/main.go

@ -160,6 +160,7 @@ func transferFile(c *UpFileClient, curPath string, uploadPath string) error {
fmt.Println("\n文件发送完成!") fmt.Println("\n文件发送完成!")
// 文件解压缩 // 文件解压缩
distFullName := filepath.Join(dirPath, fileName) distFullName := filepath.Join(dirPath, fileName)
fmt.Printf("distFullName: %s\n", distFullName)
// 此时调用远程的完整路径,防止解压缩不成功 // 此时调用远程的完整路径,防止解压缩不成功
c.rpcClient.Call("UpFileService.UnzipArchive", FileInfo{ c.rpcClient.Call("UpFileService.UnzipArchive", FileInfo{
FileName: distFullName, FileName: distFullName,

Loading…
Cancel
Save