style: 增加计算文件夹大小接口

This commit is contained in:
zhengkunwang223
2022-09-09 18:10:41 +08:00
committed by zhengkunwang223
parent 450114f049
commit d333fae2fe
13 changed files with 141 additions and 10 deletions

View File

@@ -2,9 +2,12 @@ package files
import (
"github.com/gabriel-vasile/mimetype"
"github.com/spf13/afero"
"os"
"os/user"
"path/filepath"
"strconv"
"sync"
)
func IsSymlink(mode os.FileMode) bool {
@@ -43,6 +46,22 @@ func GetSymlink(path string) string {
return linkPath
}
func ScanDir(fs afero.Fs, path string, dirMap *sync.Map, wg *sync.WaitGroup) {
afs := &afero.Afero{Fs: fs}
files, _ := afs.ReadDir(path)
for _, f := range files {
if f.IsDir() {
wg.Add(1)
go ScanDir(fs, filepath.Join(path, f.Name()), dirMap, wg)
} else {
if f.Size() > 0 {
dirMap.Store(filepath.Join(path, f.Name()), float64(f.Size()))
}
}
}
defer wg.Done()
}
const dotCharacter = 46
func IsHidden(path string) bool {