From 81d6088c8fd69b277288e127562129aa00699c70 Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Sat, 29 Oct 2016 10:31:44 +0800 Subject: [PATCH] Unify rootfs validation Signed-off-by: Qiang Huang --- libcontainer/configs/validate/validator.go | 6 ++++++ utils_linux.go | 7 ------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/libcontainer/configs/validate/validator.go b/libcontainer/configs/validate/validator.go index 3becd31d5..3d736cff2 100644 --- a/libcontainer/configs/validate/validator.go +++ b/libcontainer/configs/validate/validator.go @@ -46,6 +46,12 @@ func (v *ConfigValidator) Validate(config *configs.Config) error { // rootfs validates if the rootfs is an absolute path and is not a symlink // to the container's root filesystem. func (v *ConfigValidator) rootfs(config *configs.Config) error { + if _, err := os.Stat(config.Rootfs); err != nil { + if os.IsNotExist(err) { + return fmt.Errorf("rootfs (%s) does not exist", config.Rootfs) + } + return err + } cleaned, err := filepath.Abs(config.Rootfs) if err != nil { return err diff --git a/utils_linux.go b/utils_linux.go index c97500b41..94c520fb0 100644 --- a/utils_linux.go +++ b/utils_linux.go @@ -179,13 +179,6 @@ func createContainer(context *cli.Context, id string, spec *specs.Spec) (libcont return nil, err } - if _, err := os.Stat(config.Rootfs); err != nil { - if os.IsNotExist(err) { - return nil, fmt.Errorf("rootfs (%q) does not exist", config.Rootfs) - } - return nil, err - } - factory, err := loadFactory(context) if err != nil { return nil, err