🎨 退出时自动删除超过 30 天的安装包 Fix https://github.com/siyuan-note/siyuan/issues/5957

This commit is contained in:
Liang Ding 2022-09-26 00:05:03 +08:00
parent 162123c3b4
commit 9eda58bf37
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

View file

@ -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)