优化代码

This commit is contained in:
GoEdgeLab
2023-08-15 15:49:23 +08:00
parent 98f33485c9
commit 42ebb4514d
4 changed files with 16 additions and 16 deletions
+5 -5
View File
@@ -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
}