From 0e5d3e25b2d8c6826359f96b5a77005f8a7119be Mon Sep 17 00:00:00 2001 From: xc Date: Fri, 26 Sep 2025 09:35:39 +0800 Subject: [PATCH] =?UTF-8?q?mysql=20binlog=E6=97=A5=E5=BF=97=E8=AF=BB?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scagent/core/FileRpc.go | 28 ++++++++++++++++++---------- scagent/core/UpFile.go | 10 +++++++--- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/scagent/core/FileRpc.go b/scagent/core/FileRpc.go index 2ee4fa5..dc33dfd 100644 --- a/scagent/core/FileRpc.go +++ b/scagent/core/FileRpc.go @@ -97,6 +97,7 @@ func clientUploadFile(remote string, filePath string, uploadPath string) { if err != nil { logger.Error("NewUpFileClient failed", zap.Error(err)) } + defer client.rpcClient.Close() // 调用 transferFile err = client.TransferFile(filePath, uploadPath) if err != nil { @@ -110,6 +111,7 @@ func clientUploadFile(remote string, filePath string, uploadPath string) { // 传输文件 func (c *UpFileClient) TransferFile(filePath string, uploadPath string) error { + fmt.Printf("TransferFile filePath: %s, uploadPath: %s\n", filePath, uploadPath) // 发送文件信息 // 获取文件信息 fileInfo, err := os.Stat(filePath) @@ -123,17 +125,23 @@ func (c *UpFileClient) TransferFile(filePath string, uploadPath string) error { // 远程的文件名 fileName := filepath.Base(uploadPath) fmt.Printf("fileName: %s\n", fileName) + + // 远程服务器的路径 + dirpath := filepath.Dir(uploadPath) + fmt.Printf("remote dirpath: %s\n", dirpath) + fmt.Printf("file size: %d\n", fileInfo.Size()) + // 发送文件信息 - var reply bool - err = c.rpcClient.Call("UpFileService.SendFileInfo", FileInfo{ - FileName: filePath, - FileSize: fileInfo.Size(), - }, &reply) - if err != nil { - fmt.Printf("发送文件信息失败: %v\n", err) - return err - } - fmt.Printf("replay: %v\n", reply) + var reply string + // 异步 + go func() { + c.rpcClient.Call("UpFileService.SendFileInfo", FileInfo{ + FileName: uploadPath, + FileSize: fileInfo.Size(), + }, &reply) + // 输出执行的结果 + fmt.Printf("SendFileInfo result: %s\n", reply) + }() return nil } diff --git a/scagent/core/UpFile.go b/scagent/core/UpFile.go index 1ee3e80..607e6dd 100644 --- a/scagent/core/UpFile.go +++ b/scagent/core/UpFile.go @@ -28,7 +28,7 @@ type FileChunk struct { // 发送文件的RPC // SendFile 接收文件信息(名称和大小) -func (f *UpFileService) SendFileInfo(info FileInfo, reply *bool) error { +func (f *UpFileService) SendFileInfo(info FileInfo, reply *string) error { logger := util.NewProductionLogger() defer logger.Sync() // 创建保存文件的目录 @@ -44,10 +44,14 @@ func (f *UpFileService) SendFileInfo(info FileInfo, reply *bool) error { if _, err := os.Stat(dirPath); os.IsNotExist(err) { // 文件夹不存在,创建它 if err := os.MkdirAll(dirPath, 0755); err != nil { - return err + logger.Error("SendFileInfo mkdir failed", zap.Error(err)) + *reply = fmt.Sprintf("mkdir folder: %s failed", dirPath) + // return err } } - *reply = true + + *reply = fmt.Sprintf("folder: %s is exists", dirPath) + // *reply = true return nil }