From 9eda58bf378ea01c94815833bf0ef41616acf871 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 26 Sep 2022 00:05:03 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E9=80=80=E5=87=BA=E6=97=B6=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=A0=E9=99=A4=E8=B6=85=E8=BF=87=2030=20=E5=A4=A9?= =?UTF-8?q?=E7=9A=84=E5=AE=89=E8=A3=85=E5=8C=85=20Fix=20https://github.com?= =?UTF-8?q?/siyuan-note/siyuan/issues/5957?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/conf.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/kernel/model/conf.go b/kernel/model/conf.go index 9cfc6842b..cd2145592 100644 --- a/kernel/model/conf.go +++ b/kernel/model/conf.go @@ -570,6 +570,25 @@ func clearWorkspaceTemp() { os.RemoveAll(filepath.Join(util.TempDir, "repo")) os.RemoveAll(filepath.Join(util.TempDir, "os")) + // 退出时自动删除超过 30 天的安装包 https://github.com/siyuan-note/siyuan/issues/5957 + install := filepath.Join(util.TempDir, "install") + if gulu.File.IsDir(install) { + monthAgo := time.Now().Add(-time.Hour * 24 * 30) + entries, err := os.ReadDir(install) + if nil != err { + logging.LogErrorf("read dir [%s] failed: %s", install, err) + } else { + for _, entry := range entries { + info, _ := entry.Info() + if nil != info && !info.IsDir() && info.ModTime().Before(monthAgo) { + if err = os.RemoveAll(filepath.Join(install, entry.Name())); nil != err { + logging.LogErrorf("remove old install pkg [%s] failed: %s", filepath.Join(install, entry.Name()), err) + } + } + } + } + } + tmps, err := filepath.Glob(filepath.Join(util.TempDir, "*.tmp")) if nil != err { logging.LogErrorf("glob temp files failed: %s", err)