Files
trivy/analyzer/os/common.go
Teppei Fukuda a8380ab5e5 Transfer repositoriy (fanal#27)
* Transfer repositoriy

* Disable coverall temporarily
2019-08-19 09:15:12 +01:00

39 lines
811 B
Go

package os
import (
"io/ioutil"
"os"
"path/filepath"
"github.com/aquasecurity/fanal/extractor"
"golang.org/x/xerrors"
)
// GetFileMap is test function
func GetFileMap(prefixPath string) (extractor.FileMap, error) {
fileMap := extractor.FileMap{}
err := filepath.Walk(
prefixPath,
func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
read, err := os.Open(path)
if err != nil {
return xerrors.Errorf("can't open file %s", path)
}
fileBytes, err := ioutil.ReadAll(read)
if err != nil {
return xerrors.Errorf("can't read file %s", path)
}
// delete prefix (directory) name. only leave etc/xxxx
fileMap[path[(len(prefixPath)-1):]] = fileBytes
return nil
},
)
return fileMap, err
}