Ver Fonte

Merge pull request #3915 from crosbymichael/no-double-put

No no put put
unclejack há 11 anos atrás
pai
commit
b5d6208ccf
2 ficheiros alterados com 8 adições e 4 exclusões
  1. 7 3
      container.go
  2. 1 1
      image.go

+ 7 - 3
container.go

@@ -1416,9 +1416,12 @@ func (container *Container) ExportRw() (archive.Archive, error) {
 	if container.runtime == nil {
 		return nil, fmt.Errorf("Can't load storage driver for unregistered container %s", container.ID)
 	}
-	defer container.Unmount()
-
-	return container.runtime.Diff(container)
+	archive, err := container.runtime.Diff(container)
+	if err != nil {
+		container.Unmount()
+		return nil, err
+	}
+	return EofReader(archive, func() { container.Unmount() }), nil
 }
 
 func (container *Container) Export() (archive.Archive, error) {
@@ -1428,6 +1431,7 @@ func (container *Container) Export() (archive.Archive, error) {
 
 	archive, err := archive.Tar(container.basefs, archive.Uncompressed)
 	if err != nil {
+		container.Unmount()
 		return nil, err
 	}
 	return EofReader(archive, func() { container.Unmount() }), nil

+ 1 - 1
image.go

@@ -163,7 +163,7 @@ func (img *Image) TarLayer() (arch archive.Archive, err error) {
 	}
 
 	defer func() {
-		if err == nil {
+		if err != nil {
 			driver.Put(img.ID)
 		}
 	}()