Browse code

never remove the file and try to load it in start

Victor Vieux authored on 2013/07/03 03:02:16
Showing 2 changed files
... ...
@@ -265,7 +265,7 @@ func (container *Container) ToDisk() (err error) {
265 265
 	return ioutil.WriteFile(container.jsonPath(), data, 0666)
266 266
 }
267 267
 
268
-func (container *Container) ReadTempHostConfig() (*HostConfig, error) {
268
+func (container *Container) ReadHostConfig() (*HostConfig, error) {
269 269
 	data, err := ioutil.ReadFile(container.hostConfigPath())
270 270
 	if err != nil {
271 271
 		return &HostConfig{}, err
... ...
@@ -278,9 +278,6 @@ func (container *Container) ReadTempHostConfig() (*HostConfig, error) {
278 278
 }
279 279
 
280 280
 func (container *Container) SaveHostConfig(hostConfig *HostConfig) (err error) {
281
-	if hostConfig == nil {
282
-		return os.Remove(container.hostConfigPath())
283
-	}
284 281
 	data, err := json.Marshal(hostConfig)
285 282
 	if err != nil {
286 283
 		return
... ...
@@ -491,6 +488,9 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s
491 491
 func (container *Container) Start(hostConfig *HostConfig) error {
492 492
 	container.State.lock()
493 493
 	defer container.State.unlock()
494
+	if len(hostConfig.Binds) == 0 {
495
+		hostConfig, _ = container.ReadHostConfig()
496
+	}
494 497
 
495 498
 	if container.State.Running {
496 499
 		return fmt.Errorf("The container %s is already running.", container.ID)
... ...
@@ -815,8 +815,6 @@ func (container *Container) monitor() {
815 815
 		// FIXME: why are we serializing running state to disk in the first place?
816 816
 		//log.Printf("%s: Failed to dump configuration to the disk: %s", container.ID, err)
817 817
 	}
818
-	// Remove temp host config
819
-	container.SaveHostConfig(nil)
820 818
 }
821 819
 
822 820
 func (container *Container) kill() error {
... ...
@@ -144,8 +144,7 @@ func (runtime *Runtime) Register(container *Container) error {
144 144
 				utils.Debugf("Restarting")
145 145
 				container.State.Ghost = false
146 146
 				container.State.setStopped(0)
147
-				// assume empty host config
148
-				hostConfig, _ := container.ReadTempHostConfig()
147
+				hostConfig := &HostConfig{}
149 148
 				if err := container.Start(hostConfig); err != nil {
150 149
 					return err
151 150
 				}
... ...
@@ -156,8 +155,6 @@ func (runtime *Runtime) Register(container *Container) error {
156 156
 				if err := container.ToDisk(); err != nil {
157 157
 					return err
158 158
 				}
159
-				// remove temp host config
160
-				container.SaveHostConfig(nil)
161 159
 			}
162 160
 		}
163 161
 	}