MCPcopy Create free account
hub / github.com/astercloud/aster / cleanupFiles

Method cleanupFiles

pkg/tools/cache.go:428–462  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

426}
427
428func (c *ToolCache) cleanupFiles() {
429 if _, err := os.Stat(c.config.CacheDir); os.IsNotExist(err) {
430 return
431 }
432
433 entries, err := os.ReadDir(c.config.CacheDir)
434 if err != nil {
435 c.stats.Errors++
436 return
437 }
438
439 for _, entry := range entries {
440 if entry.IsDir() {
441 continue
442 }
443
444 filePath := filepath.Join(c.config.CacheDir, entry.Name())
445
446 // 读取并检查是否过期
447 data, err := os.ReadFile(filePath)
448 if err != nil {
449 continue
450 }
451
452 var cacheEntry CacheEntry
453 if err := json.Unmarshal(data, &cacheEntry); err != nil {
454 continue
455 }
456
457 if cacheEntry.IsExpired() {
458 _ = os.Remove(filePath)
459 c.stats.Evictions++
460 }
461 }
462}
463
464// CachedTool 带缓存的工具包装器
465type CachedTool struct {

Callers 1

cleanupMethod · 0.95

Calls 6

IsExpiredMethod · 0.95
StatMethod · 0.65
NameMethod · 0.65
JoinMethod · 0.45
ReadFileMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected