From 795223e7fad35ed19347f0701c48ef28869a9a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=98=AD?= <81747598+lan-yonghui@users.noreply.github.com> Date: Tue, 17 Jun 2025 17:00:54 +0800 Subject: [PATCH] fix: Fix the issue of interface image loss caused by clearing cache (#9149) Refs: #9050 --- agent/app/service/device_clean.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/agent/app/service/device_clean.go b/agent/app/service/device_clean.go index 43807841a..ca458b6e2 100644 --- a/agent/app/service/device_clean.go +++ b/agent/app/service/device_clean.go @@ -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