Merge pull request #2473 from dotcloud/remove-panic-from-name
Assign id as name when all else fails
This commit is contained in:
commit
429c3108da
2 changed files with 10 additions and 8 deletions
10
runtime.go
10
runtime.go
|
@ -265,7 +265,10 @@ func (runtime *Runtime) restore() error {
|
|||
// Any containers that are left over do not exist in the graph
|
||||
for _, container := range containers {
|
||||
// Try to set the default name for a container if it exists prior to links
|
||||
name := generateRandomName(runtime)
|
||||
name, err := generateRandomName(runtime)
|
||||
if err != nil {
|
||||
container.Name = container.ShortID()
|
||||
}
|
||||
container.Name = name
|
||||
|
||||
if _, err := runtime.containerGraph.Set(name, container.ID); err != nil {
|
||||
|
@ -356,7 +359,10 @@ func (runtime *Runtime) Create(config *Config, name string) (*Container, []strin
|
|||
id := GenerateID()
|
||||
|
||||
if name == "" {
|
||||
name = generateRandomName(runtime)
|
||||
name, err = generateRandomName(runtime)
|
||||
if err != nil {
|
||||
name = utils.TruncateID(id)
|
||||
}
|
||||
}
|
||||
if name[0] != '/' {
|
||||
name = "/" + name
|
||||
|
|
8
utils.go
8
utils.go
|
@ -304,10 +304,6 @@ func (c *checker) Exists(name string) bool {
|
|||
}
|
||||
|
||||
// Generate a random and unique name
|
||||
func generateRandomName(runtime *Runtime) string {
|
||||
n, err := namesgenerator.GenerateRandomName(&checker{runtime})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
func generateRandomName(runtime *Runtime) (string, error) {
|
||||
return namesgenerator.GenerateRandomName(&checker{runtime})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue