1
0
forked from MTSR/mapserver
mapserver/media/repository.go

44 lines
689 B
Go
Raw Permalink Normal View History

2019-06-14 11:57:29 +03:00
package media
import (
"io/ioutil"
"os"
"strings"
)
2019-06-14 14:13:21 +03:00
func ScanDir(repo map[string][]byte, path string, ignore []string) (int, error) {
2019-06-14 11:57:29 +03:00
_, files := scan_recursive(path, ignore)
2019-06-14 14:13:21 +03:00
size := 0
2019-06-14 11:57:29 +03:00
for _, filename := range files {
if strings.HasSuffix(filename, ".png") {
file, err := os.Open(filename)
if err != nil {
2019-06-14 14:13:21 +03:00
return 0, err
2019-06-14 11:57:29 +03:00
}
content, err := ioutil.ReadAll(file)
if err != nil {
2019-06-14 14:13:21 +03:00
return 0, err
2019-06-14 11:57:29 +03:00
}
2019-06-14 14:13:21 +03:00
size += len(content)
2019-06-14 11:57:29 +03:00
simplefilename := filename
lastSlashIndex := strings.LastIndex(filename, "/")
if lastSlashIndex >= 0 {
simplefilename = filename[lastSlashIndex+1:]
}
repo[simplefilename] = content
}
}
2019-06-14 14:13:21 +03:00
return size, nil
2019-06-14 11:57:29 +03:00
}