MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / ScanGarbageCaches

Method ScanGarbageCaches

internal/caches/storage_file.go:1675–1798  ·  view source on GitHub ↗

ScanGarbageCaches 清理目录中“失联”的缓存文件 “失联”为不在HashMap中的文件

(fileCallback func(path string) error)

Source from the content-addressed store, hash-verified

1673// ScanGarbageCaches 清理目录中“失联”的缓存文件
1674// “失联”为不在HashMap中的文件
1675func (this *FileStorage) ScanGarbageCaches(fileCallback func(path string) error) error {
1676 _, isSQLite := this.list.(*SQLiteFileList)
1677 if isSQLite && !this.list.(*SQLiteFileList).HashMapIsLoaded() {
1678 return errors.New("cache list is loading")
1679 }
1680
1681 var mainDir = this.options.Dir
1682 var allDirs = []string{mainDir}
1683 var subDirs = this.subDirs // copy
1684 for _, subDir := range subDirs {
1685 allDirs = append(allDirs, subDir.Path)
1686 }
1687
1688 var countDirs = 0
1689
1690 // process progress
1691 var progressSock = gosock.NewTmpSock(teaconst.CacheGarbageSockName)
1692 _, sockErr := progressSock.SendTimeout(&gosock.Command{Code: "progress", Params: map[string]any{"progress": 0}}, 1*time.Second)
1693 var canReportProgress = sockErr == nil
1694 var lastProgress float64
1695 var countFound = 0
1696
1697 for _, subDir := range allDirs {
1698 var dir0 = subDir + "/p" + types.String(this.policy.Id)
1699 dir1Matches, err := filepath.Glob(dir0 + "/*")
1700 if err != nil {
1701 // ignore error
1702 continue
1703 }
1704
1705 for _, dir1 := range dir1Matches {
1706 if len(filepath.Base(dir1)) != 2 {
1707 continue
1708 }
1709
1710 dir2Matches, globErr := filepath.Glob(dir1 + "/*")
1711 if globErr != nil {
1712 // ignore error
1713 continue
1714 }
1715 for _, dir2 := range dir2Matches {
1716 if len(filepath.Base(dir2)) != 2 {
1717 continue
1718 }
1719
1720 countDirs++
1721
1722 // report progress
1723 if canReportProgress {
1724 var progress = float64(countDirs) / 65536
1725 if fmt.Sprintf("%.2f", lastProgress) != fmt.Sprintf("%.2f", progress) {
1726 lastProgress = progress
1727 _, _ = progressSock.SendTimeout(&gosock.Command{Code: "progress", Params: map[string]any{
1728 "progress": progress,
1729 "count": countFound,
1730 }}, 100*time.Millisecond)
1731 }
1732 }

Callers

nothing calls this directly

Calls 6

NowFunction · 0.92
UnixMethod · 0.80
StatMethod · 0.65
HashMapIsLoadedMethod · 0.45
StringMethod · 0.45
ExistQuickMethod · 0.45

Tested by

no test coverage detected