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

Method checkDiskSpace

internal/caches/storage_file.go:1585–1625  ·  view source on GitHub ↗

检查磁盘剩余空间

()

Source from the content-addressed store, hash-verified

1583
1584// 检查磁盘剩余空间
1585func (this *FileStorage) checkDiskSpace() {
1586 var minFreeSize = DefaultMinDiskFreeSpace
1587
1588 var options = this.options // copy
1589 if options != nil && options.MinFreeSize != nil && options.MinFreeSize.Bytes() > 0 {
1590 minFreeSize = uint64(options.MinFreeSize.Bytes())
1591 }
1592
1593 if options != nil && len(options.Dir) > 0 {
1594 stat, err := fsutils.StatDevice(options.Dir)
1595 if err == nil {
1596 this.mainDiskIsFull = stat.FreeSize() < minFreeSize
1597 this.mainDiskTotalSize = stat.TotalSize()
1598
1599 // check capacity (only on main directory) when node capacity had not been set
1600 if !this.mainDiskIsFull {
1601 var capacityBytes int64
1602 var maxDiskCapacity = SharedManager.MaxDiskCapacity // copy
1603 if maxDiskCapacity != nil && maxDiskCapacity.Bytes() > 0 {
1604 capacityBytes = SharedManager.MaxDiskCapacity.Bytes()
1605 } else {
1606 var policy = this.policy // copy
1607 if policy != nil {
1608 capacityBytes = policy.CapacityBytes() // copy
1609 }
1610 }
1611
1612 if capacityBytes > 0 && stat.UsedSize() >= uint64(capacityBytes) {
1613 this.mainDiskIsFull = true
1614 }
1615 }
1616 }
1617 }
1618 var subDirs = this.subDirs // copy slice
1619 for _, subDir := range subDirs {
1620 stat, err := fsutils.StatDevice(subDir.Path)
1621 if err == nil {
1622 subDir.IsFull = stat.FreeSize() < minFreeSize
1623 }
1624 }
1625}
1626
1627// 检查是否有已满的磁盘分区
1628func (this *FileStorage) hasFullDisk() bool {

Callers 3

UpdatePolicyMethod · 0.95
InitMethod · 0.95
hasFullDiskMethod · 0.95

Calls 4

BytesMethod · 0.80
FreeSizeMethod · 0.80
UsedSizeMethod · 0.80
TotalSizeMethod · 0.45

Tested by

no test coverage detected