Browse Source

远程调用解压缩

master
xyiege 1 month ago
parent
commit
aa09341384
  1. 24
      scagent/core/UpFile.go

24
scagent/core/UpFile.go

@ -37,21 +37,16 @@ func (f *UpFileService) SendFileInfo(info FileInfo, reply *string) error {
// }
// 提取路径 /www/wwwroot/bidemo.com/BIU_20250918_183144.zip
// fmt.Printf("SendFileInfo fileName: %s\n", info.FileName)
dirPath := filepath.Dir(info.FileName)
logger.Info("SendFileInfo", zap.String("dirPath", dirPath))
// *reply = fmt.Sprintf("folder: %s is exists", dirPath)
// 检查文件夹是否存在
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
// 文件夹不存在,创建它
if err := os.MkdirAll(dirPath, 0755); err != nil {
logger.Error("SendFileInfo mkdir failed", zap.Error(err))
// *reply = fmt.Sprintf("mkdir folder: %s failed", dirPath)
// return err
}
}
// *reply = fmt.Sprintf("folder: %s is exists", dirPath)
// 返回true的字符串
*reply = "true"
return nil
@ -88,3 +83,22 @@ func (f *UpFileService) SendFileChunk(chunk FileChunk, reply *bool) error {
*reply = true
return nil
}
// 解压缩文件
// info.FileName 压缩包全路径
func (f *UpFileService) UnzipArchive(info FileInfo, reply *string) error {
// 日志
logger := util.NewProductionLogger()
defer logger.Sync()
// 解压缩文件
ret := make(chan string)
go func() {
util.DecompressZip(info.FileName)
ret <- "uzok"
}()
// 返回true的字符串
if retMsg := <-ret; retMsg == "uzok" {
*reply = retMsg
}
return nil
}

Loading…
Cancel
Save