Browse Source

fix virtual size on images

Victor Vieux 12 years ago
parent
commit
00cf2a1fa2
4 changed files with 17 additions and 19 deletions
  1. 11 12
      api_params.go
  2. 2 2
      commands.go
  3. 2 3
      image.go
  4. 2 2
      server.go

+ 11 - 12
api_params.go

@@ -7,13 +7,12 @@ type APIHistory struct {
 }
 
 type APIImages struct {
-	Repository string `json:",omitempty"`
-	Tag        string `json:",omitempty"`
-	ID         string `json:"Id"`
-	Created    int64
-	Size       int64
-	ParentSize int64
-
+	Repository  string `json:",omitempty"`
+	Tag         string `json:",omitempty"`
+	ID          string `json:"Id"`
+	Created     int64
+	Size        int64
+	VirtualSize int64
 }
 
 type APIInfo struct {
@@ -28,11 +27,11 @@ type APIInfo struct {
 
 type APIContainers struct {
 	ID         string `json:"Id"`
-	Image      string 
-	Command    string 
-	Created    int64  
-	Status     string 
-	Ports      string 
+	Image      string
+	Command    string
+	Created    int64
+	Status     string
+	Ports      string
 	SizeRw     int64
 	SizeRootFs int64
 }

+ 2 - 2
commands.go

@@ -812,8 +812,8 @@ func (cli *DockerCli) CmdImages(args ...string) error {
 					fmt.Fprintf(w, "%s\t", utils.TruncateID(out.ID))
 				}
 				fmt.Fprintf(w, "%s ago\t", utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))))
-				if out.ParentSize > 0 {
-					fmt.Fprintf(w, "%s (virtual %s)\n", utils.HumanSize(out.Size), utils.HumanSize(out.ParentSize))
+				if out.VirtualSize > 0 {
+					fmt.Fprintf(w, "%s (virtual %s)\n", utils.HumanSize(out.Size), utils.HumanSize(out.VirtualSize))
 				} else {
 					fmt.Fprintf(w, "%s\n", utils.HumanSize(out.Size))
 				}

+ 2 - 3
image.go

@@ -31,7 +31,6 @@ type Image struct {
 	Architecture    string    `json:"architecture,omitempty"`
 	graph           *Graph
 	Size            int64
-	ParentSize      int64
 }
 
 func LoadImage(root string) (*Image, error) {
@@ -376,13 +375,13 @@ func (img *Image) Checksum() (string, error) {
 	return hash, nil
 }
 
-func (img *Image) getVirtualSize(size int64) int64 {
+func (img *Image) getParentsSize(size int64) int64 {
 	parentImage, err := img.GetParent()
 	if err != nil || parentImage == nil {
 		return size
 	}
 	size += parentImage.Size
-	return parentImage.getVirtualSize(size)
+	return parentImage.getParentsSize(size)
 }
 
 // Build an Image object from raw json data

+ 2 - 2
server.go

@@ -177,7 +177,7 @@ func (srv *Server) Images(all bool, filter string) ([]APIImages, error) {
 			out.ID = image.ID
 			out.Created = image.Created.Unix()
 			out.Size = image.Size
-			out.ParentSize = image.getVirtualSize(0)
+			out.VirtualSize = image.getParentsSize(0) + image.Size
 			outs = append(outs, out)
 		}
 	}
@@ -188,7 +188,7 @@ func (srv *Server) Images(all bool, filter string) ([]APIImages, error) {
 			out.ID = image.ID
 			out.Created = image.Created.Unix()
 			out.Size = image.Size
-			out.ParentSize = image.getVirtualSize(0)
+			out.VirtualSize = image.getParentsSize(0) + image.Size
 			outs = append(outs, out)
 		}
 	}