Merge pull request #455 from Mashimiao/bundle-add-check-before-Load

bundle: add check before Load return
This commit is contained in:
Stephen Day 2017-01-23 15:48:56 -08:00 committed by GitHub
commit 3b79682548
1 changed files with 9 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import (
"path/filepath"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
)
const configName = "config.json"
@ -36,7 +37,14 @@ func New(path string, s *specs.Spec) (*Bundle, error) {
}
func Load(path string) (*Bundle, error) {
// TODO: do validation
fi, err := os.Stat(path)
if err != nil {
return nil, errors.Wrapf(err, "failed to access %q", path)
}
if !fi.IsDir() {
return nil, errors.Errorf("%q is not a directory", path)
}
return &Bundle{
Path: path,
}, nil