fix: mk cache dir

This commit is contained in:
krau
2024-10-12 13:27:39 +08:00
parent d5f214494c
commit 0bd9b77856
2 changed files with 17 additions and 2 deletions

View File

@@ -33,6 +33,18 @@ func PurgeFile(path string) error {
return RemoveEmptyDirectories(filepath.Dir(path))
}
func RmFileAfter(path string, td time.Duration) {
_, err := os.Stat(path)
if err != nil {
logger.L.Errorf("Failed to create timer for %s: %s", path, err)
return
}
logger.L.Debugf("Remove file after %s: %s", td, path)
time.AfterFunc(td, func() {
PurgeFile(path)
})
}
// 递归删除空目录
func RemoveEmptyDirectories(dirPath string) error {
entries, err := os.ReadDir(dirPath)