Skip to content

Commit

Permalink
fix virtual size on images
Browse files Browse the repository at this point in the history
  • Loading branch information
vieux committed Jun 14, 2013
1 parent bf63cb9 commit 00cf2a1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
23 changes: 11 additions & 12 deletions api_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
5 changes: 2 additions & 3 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type Image struct {
Architecture string `json:"architecture,omitempty"`
graph *Graph
Size int64
ParentSize int64
}

func LoadImage(root string) (*Image, error) {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 00cf2a1

Please sign in to comment.