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 { type APIImages struct {
Repository string `json:",omitempty"` Repository string `json:",omitempty"`
Tag string `json:",omitempty"` Tag string `json:",omitempty"`
ID string `json:"Id"` ID string `json:"Id"`
Created int64 Created int64
Size int64 Size int64
ParentSize int64 VirtualSize int64
} }
type APIInfo struct { type APIInfo struct {

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\t", utils.TruncateID(out.ID))
} }
fmt.Fprintf(w, "%s ago\t", utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0)))) fmt.Fprintf(w, "%s ago\t", utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))))
if out.ParentSize > 0 { if out.VirtualSize > 0 {
fmt.Fprintf(w, "%s (virtual %s)\n", utils.HumanSize(out.Size), utils.HumanSize(out.ParentSize)) fmt.Fprintf(w, "%s (virtual %s)\n", utils.HumanSize(out.Size), utils.HumanSize(out.VirtualSize))
} else { } else {
fmt.Fprintf(w, "%s\n", utils.HumanSize(out.Size)) fmt.Fprintf(w, "%s\n", utils.HumanSize(out.Size))
} }

View file

@ -31,7 +31,6 @@ type Image struct {
Architecture string `json:"architecture,omitempty"` Architecture string `json:"architecture,omitempty"`
graph *Graph graph *Graph
Size int64 Size int64
ParentSize int64
} }
func LoadImage(root string) (*Image, error) { func LoadImage(root string) (*Image, error) {
@ -376,13 +375,13 @@ func (img *Image) Checksum() (string, error) {
return hash, nil return hash, nil
} }
func (img *Image) getVirtualSize(size int64) int64 { func (img *Image) getParentsSize(size int64) int64 {
parentImage, err := img.GetParent() parentImage, err := img.GetParent()
if err != nil || parentImage == nil { if err != nil || parentImage == nil {
return size return size
} }
size += parentImage.Size size += parentImage.Size
return parentImage.getVirtualSize(size) return parentImage.getParentsSize(size)
} }
// Build an Image object from raw json data // 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.ID = image.ID
out.Created = image.Created.Unix() out.Created = image.Created.Unix()
out.Size = image.Size out.Size = image.Size
out.ParentSize = image.getVirtualSize(0) out.VirtualSize = image.getParentsSize(0) + image.Size
outs = append(outs, out) outs = append(outs, out)
} }
} }
@ -188,7 +188,7 @@ func (srv *Server) Images(all bool, filter string) ([]APIImages, error) {
out.ID = image.ID out.ID = image.ID
out.Created = image.Created.Unix() out.Created = image.Created.Unix()
out.Size = image.Size out.Size = image.Size
out.ParentSize = image.getVirtualSize(0) out.VirtualSize = image.getParentsSize(0) + image.Size
outs = append(outs, out) outs = append(outs, out)
} }
} }