bundle: add check before Load return

Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
This commit is contained in:
Ma Shimiao 2017-01-20 16:52:33 +08:00
parent 7101c7a9e2
commit ffc4c570af
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