fix:清理集群同步数据时的临时文件

This commit is contained in:
gotoeasy 2025-04-30 20:42:50 +08:00
parent d1772a0304
commit b875fe7168
2 changed files with 10 additions and 0 deletions

View File

@ -95,6 +95,7 @@ func checkAndCopyDataFromRemote() {
cmn.Info("本地无日志仓", k, "开始从", remoteStore.NodeUrl, "复制", remoteStore.Name)
tarfile, err := httpDownloadStoreFile(remoteStore.NodeUrl, remoteStore.Name) // 下载
if err != nil {
cmn.RemoveAllFile(tarfile)
continue
}
@ -103,6 +104,7 @@ func checkAndCopyDataFromRemote() {
distDir := filepath.Join(conf.GetStorageRoot(), storeName)
cmn.MkdirAll(distDir)
cmn.UnTar(tarfile, distDir)
cmn.RemoveAllFile(tarfile)
// 保存信息
sysdb := sysmnt.NewSysmntStorage()

View File

@ -40,5 +40,13 @@ func ClusterDownloadStoreDataController(req *gweb.HttpRequest) *gweb.HttpResult
ctx.Header("Content-Transfer-Encoding", "binary")
ctx.File(tarfilename)
go deleteTarfilename(tarfilename)
return nil
}
func deleteTarfilename(tarfilename string) {
// 5分钟后删除
time.Sleep(5 * time.Minute)
cmn.RemoveAllFile(tarfilename)
}