From ffc4c570af5904c3b8d067401441a8661181b5a2 Mon Sep 17 00:00:00 2001 From: Ma Shimiao Date: Fri, 20 Jan 2017 16:52:33 +0800 Subject: [PATCH] bundle: add check before Load return Signed-off-by: Ma Shimiao --- bundle/bundle.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bundle/bundle.go b/bundle/bundle.go index 68da885..734b91c 100644 --- a/bundle/bundle.go +++ b/bundle/bundle.go @@ -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