-
Notifications
You must be signed in to change notification settings - Fork 19
/
lister.go
51 lines (41 loc) · 1.04 KB
/
lister.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package groot
import (
"os"
"path/filepath"
"code.cloudfoundry.org/grootfs/store"
"code.cloudfoundry.org/lager"
errorspkg "github.com/pkg/errors"
)
type Lister struct {
}
func IamLister() *Lister {
return &Lister{}
}
func (l *Lister) List(logger lager.Logger, storePath string) ([]string, error) {
logger = logger.Session("groot-listing", lager.Data{"storePath": storePath})
logger.Info("starting")
defer logger.Info("ending")
imagePaths, err := l.listDirs(filepath.Join(storePath, store.ImageDirName))
if err != nil {
return nil, errorspkg.Wrap(err, "failed to list store path")
}
logger.Debug("list-images", lager.Data{"imagePaths": imagePaths})
return imagePaths, nil
}
func (l *Lister) listDirs(path string) ([]string, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
files, err := f.Readdir(-1)
_ = f.Close()
if err != nil {
return nil, err
}
names := []string{}
for _, fileInfo := range files {
fullPath := filepath.Join(path, fileInfo.Name())
names = append(names, fullPath)
}
return names, nil
}