show repo size of media catalog

This commit is contained in:
NatureFreshMilk 2019-06-14 13:13:21 +02:00
parent fbf2c1c190
commit 8bcbd877e8
2 changed files with 13 additions and 6 deletions

View File

@ -146,8 +146,12 @@ func Setup(p params.ParamsType, cfg *Config) *App {
//create media repo
repo := make(map[string][]byte)
media.ScanDir(repo, ".", []string{"mapserver.tiles", ".git"})
logrus.WithFields(logrus.Fields{"count": len(repo)}).Info("Created media repository")
mediasize, _ := media.ScanDir(repo, ".", []string{"mapserver.tiles", ".git"})
fields := logrus.Fields{
"count": len(repo),
"bytes": mediasize,
}
logrus.WithFields(fields).Info("Created media repository")
a.MediaRepo = repo

View File

@ -6,8 +6,9 @@ import (
"strings"
)
func ScanDir(repo map[string][]byte, path string, ignore []string) error {
func ScanDir(repo map[string][]byte, path string, ignore []string) (int, error) {
_, files := scan_recursive(path, ignore)
size := 0
for _, filename := range files {
if strings.HasSuffix(filename, ".png") {
@ -15,15 +16,17 @@ func ScanDir(repo map[string][]byte, path string, ignore []string) error {
file, err := os.Open(filename)
if err != nil {
return err
return 0, err
}
content, err := ioutil.ReadAll(file)
if err != nil {
return err
return 0, err
}
size += len(content)
simplefilename := filename
lastSlashIndex := strings.LastIndex(filename, "/")
@ -36,5 +39,5 @@ func ScanDir(repo map[string][]byte, path string, ignore []string) error {
}
return nil
return size, nil
}