2019-09-02 00:58:20 +03:00
|
|
|
package memware
|
2019-09-01 00:00:24 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/markbates/pkger/fs"
|
|
|
|
)
|
|
|
|
|
2019-09-02 00:54:05 +03:00
|
|
|
func (f *Warehouse) Walk(p string, wf filepath.WalkFunc) error {
|
2019-09-01 00:00:24 +03:00
|
|
|
keys := f.files.Keys()
|
|
|
|
|
|
|
|
pt, err := f.Parse(p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, k := range keys {
|
|
|
|
if !strings.HasPrefix(k.Name, pt.Name) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fl, ok := f.files.Load(k)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("could not find %s", k)
|
|
|
|
}
|
|
|
|
fi, err := fl.Stat()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fi = fs.WithName(strings.TrimPrefix(k.Name, pt.Name), fi)
|
|
|
|
err = wf(k.String(), fi, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|