获取目录
(hash string)
| 1643 | |
| 1644 | // 获取目录 |
| 1645 | func (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中的文件 |
no test coverage detected