fix: Fix the issue of interface image loss caused by clearing cache (#9149)

Refs: #9050
This commit is contained in:
2025-06-17 17:00:54 +08:00 committed by GitHub
parent 10039c6173
commit 795223e7fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path"
"path/filepath"
"sort"
"strings"
"time"
@ -338,7 +339,7 @@ func doSystemClean(taskItem *task.Task) func(t *task.Task) error {
}
dropWithTask(path.Join(global.Dir.BaseDir, tmpUploadPath), taskItem, &size, &fileCount)
dropWithTask(path.Join(global.Dir.BaseDir, uploadPath), taskItem, &size, &fileCount)
dropWithExclude(path.Join(global.Dir.BaseDir, uploadPath), []string{"theme"}, taskItem, &size, &fileCount)
dropWithTask(path.Join(global.Dir.BaseDir, downloadPath), taskItem, &size, &fileCount)
logFiles, _ := os.ReadDir(global.Dir.LogDir)
@ -714,6 +715,30 @@ func dropVolumes() {
}
}
func dropWithExclude(pathToDelete string, excludeSubDirs []string, taskItem *task.Task, size *int64, count *int) {
entries, err := os.ReadDir(pathToDelete)
if err != nil {
taskItem.LogFailed(fmt.Sprintf("read dir %s failed: %v", pathToDelete, err))
return
}
for _, entry := range entries {
name := entry.Name()
fullPath := filepath.Join(pathToDelete, name)
excluded := false
for _, ex := range excludeSubDirs {
if name == ex {
excluded = true
break
}
}
if excluded {
continue
}
dropWithTask(fullPath, taskItem, size, count)
}
}
func dropWithTask(itemPath string, taskItem *task.Task, size *int64, count *int) {
itemSize := int64(0)
itemCount := 0