From b1d7f9c18412f6290f548cba986bfd0bbcd3c9ae Mon Sep 17 00:00:00 2001 From: xc Date: Thu, 23 Oct 2025 19:04:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8F=91=E9=80=81=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=B7=AF=E5=BE=84=E9=94=99=E8=AF=AF=E7=9A=84=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scagent/core/FileRpc.go | 4 +++- scagent/util/fsutil.go | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/scagent/core/FileRpc.go b/scagent/core/FileRpc.go index cc54fc7..4f56c7e 100644 --- a/scagent/core/FileRpc.go +++ b/scagent/core/FileRpc.go @@ -61,8 +61,10 @@ func (f *FileService) Compress(args *ZipBlock, reply *string) error { // 日志输出 logger.Info("压缩文件", zap.String("filename", zpFileName), zap.String("path", realFilePath)) }() + // 年月格式的目录 + dirpath := fmt.Sprintf("%d/%02d", time.Now().Year(), time.Now().Month()) // ZIP 文件的实际路径 - ziprl := path.Join(config.G.FilePath, "/sync_zips", zpFileName) + ziprl := path.Join(config.G.FilePath, "/sync_zips", dirpath, zpFileName) // zip 创建成功后 rest := <-taskId // 如果压缩包生成成功以后再执行 diff --git a/scagent/util/fsutil.go b/scagent/util/fsutil.go index 646e863..5ae444b 100644 --- a/scagent/util/fsutil.go +++ b/scagent/util/fsutil.go @@ -335,7 +335,7 @@ func CompressToZip(dest string, currentPath string, paths []string) error { fmt.Println(err.Error()) } // ToSlash 过滤windows的斜杠引起的bug - zfile, err := os.Create(path.Join(filesPath, dest)) + zfile, err := os.Create(path.Join("./sync_zips", "/", dest)) if err != nil { return err } @@ -409,7 +409,8 @@ func CompressToZip(dest string, currentPath string, paths []string) error { } } // 存到指定位置 - os.Rename(dest, path.Join("./sync_zips/", dest)) + // os.Rename(dest, path.Join("./sync_zips/", dest)) + os.Rename(path.Join("./sync_zips/", dest), path.Join(filesPath, dest)) return nil }