diff --git a/internal/caches/storage_file.go b/internal/caches/storage_file.go index 438992a..3344c94 100644 --- a/internal/caches/storage_file.go +++ b/internal/caches/storage_file.go @@ -1418,14 +1418,14 @@ func (this *FileStorage) checkDiskSpace() { if this.options != nil && len(this.options.Dir) > 0 { stat, err := fsutils.Stat(this.options.Dir) if err == nil { - this.mainDiskIsFull = stat.AvailableSize() < MinDiskSpace + this.mainDiskIsFull = stat.FreeSize() < MinDiskSpace } } var subDirs = this.subDirs // copy slice for _, subDir := range subDirs { stat, err := fsutils.Stat(subDir.Path) if err == nil { - subDir.IsFull = stat.AvailableSize() < MinDiskSpace + subDir.IsFull = stat.FreeSize() < MinDiskSpace } } } diff --git a/internal/nodes/node_status_executor.go b/internal/nodes/node_status_executor.go index 1cf0593..cb56c59 100644 --- a/internal/nodes/node_status_executor.go +++ b/internal/nodes/node_status_executor.go @@ -286,7 +286,7 @@ func (this *NodeStatusExecutor) updateCacheSpace(status *nodeconfigs.NodeStatus) result = append(result, maps.Map{ "path": path, "total": stat.TotalSize(), - "avail": stat.AvailableSize(), + "avail": stat.FreeSize(), "used": stat.UsedSize(), }) } diff --git a/internal/utils/fs/stat.go b/internal/utils/fs/stat.go index 9eaac30..2fc847b 100644 --- a/internal/utils/fs/stat.go +++ b/internal/utils/fs/stat.go @@ -65,8 +65,8 @@ func NewStatResult(rawStat *unix.Statfs_t) *StatResult { } } -func (this *StatResult) AvailableSize() uint64 { - return this.rawStat.Bavail * this.blockSize +func (this *StatResult) FreeSize() uint64 { + return this.rawStat.Bfree * this.blockSize } func (this *StatResult) TotalSize() uint64 { @@ -74,8 +74,8 @@ func (this *StatResult) TotalSize() uint64 { } func (this *StatResult) UsedSize() uint64 { - if this.rawStat.Bavail <= this.rawStat.Blocks { - return (this.rawStat.Blocks - this.rawStat.Bavail) * this.blockSize + if this.rawStat.Bfree <= this.rawStat.Blocks { + return (this.rawStat.Blocks - this.rawStat.Bfree) * this.blockSize } return 0 } diff --git a/internal/utils/fs/stat_test.go b/internal/utils/fs/stat_test.go index e9f36b0..e8490c9 100644 --- a/internal/utils/fs/stat_test.go +++ b/internal/utils/fs/stat_test.go @@ -14,7 +14,7 @@ func TestStat(t *testing.T) { if err != nil { t.Fatal(err) } - t.Log("available:", stat.AvailableSize()/(1<<30), "total:", stat.TotalSize()/(1<<30), "used:", stat.UsedSize()/(1<<30)) + t.Log("free:", stat.FreeSize()/(1<<30), "total:", stat.TotalSize()/(1<<30), "used:", stat.UsedSize()/(1<<30)) } func TestStatCache(t *testing.T) { @@ -23,7 +23,7 @@ func TestStatCache(t *testing.T) { if err != nil { t.Fatal(err) } - t.Log("available:", stat.AvailableSize()/(1<<30), "total:", stat.TotalSize()/(1<<30), "used:", stat.UsedSize()/(1<<30)) + t.Log("free:", stat.FreeSize()/(1<<30), "total:", stat.TotalSize()/(1<<30), "used:", stat.UsedSize()/(1<<30)) } }