1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

fix virtual size on images

This commit is contained in:
Victor Vieux 2013-06-14 10:05:01 +00:00
parent bf63cb9045
commit 00cf2a1fa2
4 changed files with 17 additions and 19 deletions

View file

@ -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
}

View file

@ -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))
}

View file

@ -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

View file

@ -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)
}
}