Skip to content

Commit

Permalink
Validate that root and state paths are different.
Browse files Browse the repository at this point in the history
Using the same path for both results in confusing errors when runtime.newBundle()
attempts to create the directories for the Task

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
  • Loading branch information
dnephin committed Nov 10, 2017
1 parent b4a65de commit 49af59b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 6 additions & 3 deletions server/server.go
Expand Up @@ -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
}
Expand Down
17 changes: 17 additions & 0 deletions server/server_test.go
@@ -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")
}

0 comments on commit 49af59b

Please sign in to comment.