Merge pull request #6121 from unclejack/refactor_daemon_restore

optimize restore & use Getenv less in daemon.go
This commit is contained in:
Michael Crosby 2014-05-30 11:37:12 -07:00
Родитель 9e58a77e26 0fd0deb75d
Коммит 251de0887b
1 изменённых файлов: 12 добавлений и 12 удалений

Просмотреть файл

@ -327,7 +327,9 @@ func (daemon *Daemon) Destroy(container *Container) error {
} }
func (daemon *Daemon) restore() error { func (daemon *Daemon) restore() error {
if os.Getenv("DEBUG") == "" && os.Getenv("TEST") == "" { debug := (os.Getenv("DEBUG") != "" || os.Getenv("TEST") != "")
if !debug {
fmt.Printf("Loading containers: ") fmt.Printf("Loading containers: ")
} }
dir, err := ioutil.ReadDir(daemon.repository) dir, err := ioutil.ReadDir(daemon.repository)
@ -340,7 +342,7 @@ func (daemon *Daemon) restore() error {
for _, v := range dir { for _, v := range dir {
id := v.Name() id := v.Name()
container, err := daemon.load(id) container, err := daemon.load(id)
if os.Getenv("DEBUG") == "" && os.Getenv("TEST") == "" { if !debug {
fmt.Print(".") fmt.Print(".")
} }
if err != nil { if err != nil {
@ -357,20 +359,16 @@ func (daemon *Daemon) restore() error {
} }
} }
registerContainer := func(container *Container) {
if err := daemon.register(container, false); err != nil {
utils.Debugf("Failed to register container %s: %s", container.ID, err)
}
}
if entities := daemon.containerGraph.List("/", -1); entities != nil { if entities := daemon.containerGraph.List("/", -1); entities != nil {
for _, p := range entities.Paths() { for _, p := range entities.Paths() {
if os.Getenv("DEBUG") == "" && os.Getenv("TEST") == "" { if !debug {
fmt.Print(".") fmt.Print(".")
} }
e := entities[p] e := entities[p]
if container, ok := containers[e.ID()]; ok { if container, ok := containers[e.ID()]; ok {
registerContainer(container) if err := daemon.register(container, false); err != nil {
utils.Debugf("Failed to register container %s: %s", container.ID, err)
}
delete(containers, e.ID()) delete(containers, e.ID())
} }
} }
@ -383,11 +381,13 @@ func (daemon *Daemon) restore() error {
if err != nil { if err != nil {
utils.Debugf("Setting default id - %s", err) utils.Debugf("Setting default id - %s", err)
} }
registerContainer(container) if err := daemon.register(container, false); err != nil {
utils.Debugf("Failed to register container %s: %s", container.ID, err)
}
} }
daemon.idIndex.UpdateSuffixarray() daemon.idIndex.UpdateSuffixarray()
if os.Getenv("DEBUG") == "" && os.Getenv("TEST") == "" { if !debug {
fmt.Printf(": done.\n") fmt.Printf(": done.\n")
} }