MCPcopy Create free account
hub / github.com/evilsocket/sum / ListPath

Function ListPath

storage/loader.go:20–46  ·  view source on GitHub ↗

ListPath enumerates .dat files in a given folder and returns the same folder as an absolute path and a map of files.

(dataPath string)

Source from the content-addressed store, hash-verified

18// ListPath enumerates .dat files in a given folder and returns the
19// same folder as an absolute path and a map of files.
20func ListPath(dataPath string) (string, map[string]string, error) {
21 dataPath, _ = filepath.Abs(dataPath)
22 if info, err := os.Stat(dataPath); err != nil {
23 return "", nil, err
24 } else if !info.IsDir() {
25 return "", nil, fmt.Errorf("%s is not a folder", dataPath)
26 }
27
28 files, err := ioutil.ReadDir(dataPath)
29 if err != nil {
30 return "", nil, err
31 }
32
33 loadable := make(map[string]string)
34 for _, file := range files {
35 fileName := file.Name()
36 fileExt := filepath.Ext(fileName)
37 if fileExt != DatFileExt {
38 continue
39 }
40
41 fileID := strings.Replace(fileName, DatFileExt, "", -1)
42 loadable[fileID] = filepath.Join(dataPath, fileName)
43 }
44
45 return dataPath, loadable, nil
46}
47
48// Load reads and deserializes a file into a generic protobuf message.
49func Load(fileName string, m proto.Message) error {

Callers 4

LoadMethod · 0.85
TestLoaderListPathFunction · 0.85
TestLoaderLoadFunction · 0.85

Calls 1

NameMethod · 0.65

Tested by 3

TestLoaderListPathFunction · 0.68
TestLoaderLoadFunction · 0.68