Merge pull request #1741 from dnephin/fix-task-path-conflict
Validate that root and state paths are different
This commit is contained in:
commit
a74148ba27
@ -39,12 +39,15 @@ import (
|
||||
|
||||
// New creates and initializes a new containerd server
|
||||
func New(ctx context.Context, config *Config) (*Server, error) {
|
||||
if config.Root == "" {
|
||||
switch {
|
||||
case config.Root == "":
|
||||
return nil, errors.New("root must be specified")
|
||||
}
|
||||
if config.State == "" {
|
||||
case config.State == "":
|
||||
return nil, errors.New("state must be specified")
|
||||
case config.Root == config.State:
|
||||
return nil, errors.New("root and state must be different paths")
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(config.Root, 0711); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
17
server/server_test.go
Normal file
17
server/server_test.go
Normal file
@ -0,0 +1,17 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestNewErrorsWithSamePathForRootAndState(t *testing.T) {
|
||||
path := "/tmp/path/for/testing"
|
||||
_, err := New(context.Background(), &Config{
|
||||
Root: path,
|
||||
State: path,
|
||||
})
|
||||
assert.EqualError(t, err, "root and state must be different paths")
|
||||
}
|
Loading…
Reference in New Issue
Block a user