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

Method subDir

internal/caches/storage_file.go:1645–1671  ·  view source on GitHub ↗

获取目录

(hash string)

Source from the content-addressed store, hash-verified

1643
1644// 获取目录
1645func (this *FileStorage) subDir(hash string) (dirPath string, dirIsFull bool) {
1646 var suffix = "/p" + types.String(this.policy.Id) + "/" + hash[:2] + "/" + hash[2:4]
1647
1648 if len(hash) < 4 {
1649 return this.options.Dir + suffix, this.mainDiskIsFull
1650 }
1651
1652 var subDirs = this.subDirs // copy slice
1653 var countSubDirs = len(subDirs)
1654 if countSubDirs == 0 {
1655 return this.options.Dir + suffix, this.mainDiskIsFull
1656 }
1657
1658 countSubDirs++ // add main dir
1659
1660 // 最多只支持16个目录
1661 if countSubDirs > 16 {
1662 countSubDirs = 16
1663 }
1664
1665 var dirIndex = this.charCode(hash[0]) % uint8(countSubDirs)
1666 if dirIndex == 0 {
1667 return this.options.Dir + suffix, this.mainDiskIsFull
1668 }
1669 var subDir = subDirs[dirIndex-1]
1670 return subDir.Path + suffix, subDir.IsFull
1671}
1672
1673// ScanGarbageCaches 清理目录中“失联”的缓存文件
1674// “失联”为不在HashMap中的文件

Callers 3

openWriterMethod · 0.95
keyPathMethod · 0.95
hashPathMethod · 0.95

Calls 2

charCodeMethod · 0.95
StringMethod · 0.45

Tested by

no test coverage detected