diff --git a/internal/caches/storage_file.go b/internal/caches/storage_file.go index 062aee0..0e26fce 100644 --- a/internal/caches/storage_file.go +++ b/internal/caches/storage_file.go @@ -890,7 +890,7 @@ func (this *FileStorage) Stop() { // TotalDiskSize 消耗的磁盘尺寸 func (this *FileStorage) TotalDiskSize() int64 { - stat, err := fsutils.StatCache(this.options.Dir) + stat, err := fsutils.StatDeviceCache(this.options.Dir) if err == nil { return int64(stat.UsedSize()) } @@ -1434,14 +1434,14 @@ func (this *FileStorage) checkDiskSpace() { } if options != nil && len(options.Dir) > 0 { - stat, err := fsutils.Stat(options.Dir) + stat, err := fsutils.StatDevice(options.Dir) if err == nil { this.mainDiskIsFull = stat.FreeSize() < minFreeSize } } var subDirs = this.subDirs // copy slice for _, subDir := range subDirs { - stat, err := fsutils.Stat(subDir.Path) + stat, err := fsutils.StatDevice(subDir.Path) if err == nil { subDir.IsFull = stat.FreeSize() < minFreeSize } diff --git a/internal/nodes/node_status_executor.go b/internal/nodes/node_status_executor.go index 4378112..4bfba21 100644 --- a/internal/nodes/node_status_executor.go +++ b/internal/nodes/node_status_executor.go @@ -280,7 +280,7 @@ func (this *NodeStatusExecutor) updateCacheSpace(status *nodeconfigs.NodeStatus) var result = []maps.Map{} var cachePaths = caches.SharedManager.FindAllCachePaths() for _, path := range cachePaths { - stat, err := fsutils.Stat(path) + stat, err := fsutils.StatDevice(path) if err != nil { return } diff --git a/internal/utils/fs/stat.go b/internal/utils/fs/stat.go index 2fc847b..0cf59ee 100644 --- a/internal/utils/fs/stat.go +++ b/internal/utils/fs/stat.go @@ -8,8 +8,8 @@ import ( "sync" ) -// Stat device contains the path -func Stat(path string) (*StatResult, error) { +// StatDevice device contains the path +func StatDevice(path string) (*StatResult, error) { var stat = &unix.Statfs_t{} err := unix.Statfs(path, stat) if err != nil { @@ -23,8 +23,8 @@ var cacheMap = map[string]*StatResult{} // path => StatResult const cacheLife = 3 // seconds -// StatCache stat device with cache -func StatCache(path string) (*StatResult, error) { +// StatDeviceCache stat device with cache +func StatDeviceCache(path string) (*StatResult, error) { locker.RLock() stat, ok := cacheMap[path] if ok && stat.updatedAt >= fasttime.Now().Unix()-cacheLife { @@ -36,7 +36,7 @@ func StatCache(path string) (*StatResult, error) { locker.Lock() defer locker.Unlock() - stat, err := Stat(path) + stat, err := StatDevice(path) if err != nil { return nil, err } diff --git a/internal/utils/fs/stat_test.go b/internal/utils/fs/stat_test.go index e8490c9..0adce53 100644 --- a/internal/utils/fs/stat_test.go +++ b/internal/utils/fs/stat_test.go @@ -10,7 +10,7 @@ import ( ) func TestStat(t *testing.T) { - stat, err := fsutils.Stat("/usr/local") + stat, err := fsutils.StatDevice("/usr/local") if err != nil { t.Fatal(err) } @@ -19,7 +19,7 @@ func TestStat(t *testing.T) { func TestStatCache(t *testing.T) { for i := 0; i < 10; i++ { - stat, err := fsutils.StatCache("/usr/local") + stat, err := fsutils.StatDeviceCache("/usr/local") if err != nil { t.Fatal(err) } @@ -40,16 +40,16 @@ func TestConcurrent(t *testing.T) { go func() { defer wg.Done() - _, _ = fsutils.Stat("/usr/local") + _, _ = fsutils.StatDevice("/usr/local") }() } wg.Wait() } -func BenchmarkStat(b *testing.B) { +func BenchmarkStatDevice(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { - _, err := fsutils.Stat("/usr/local") + _, err := fsutils.StatDevice("/usr/local") if err != nil { b.Fatal(err) } @@ -57,10 +57,10 @@ func BenchmarkStat(b *testing.B) { }) } -func BenchmarkStatCache(b *testing.B) { +func BenchmarkStatCacheDevice(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { - _, err := fsutils.StatCache("/usr/local") + _, err := fsutils.StatDeviceCache("/usr/local") if err != nil { b.Fatal(err) }