Merge pull request #455 from Mashimiao/bundle-add-check-before-Load
bundle: add check before Load return
This commit is contained in:
commit
3b79682548
1 changed files with 9 additions and 1 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const configName = "config.json"
|
const configName = "config.json"
|
||||||
|
@ -36,7 +37,14 @@ func New(path string, s *specs.Spec) (*Bundle, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load(path string) (*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{
|
return &Bundle{
|
||||||
Path: path,
|
Path: path,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
Loading…
Reference in a new issue