Fix image size calc on initial save
This commit is contained in:
parent
2382a0f920
commit
8fdbf46afb
2 changed files with 32 additions and 12 deletions
|
@ -1575,8 +1575,7 @@ func (container *Container) GetSize() (int64, int64) {
|
|||
}
|
||||
}
|
||||
|
||||
_, err = os.Stat(container.RootfsPath())
|
||||
if err == nil {
|
||||
if _, err = os.Stat(container.RootfsPath()); err != nil {
|
||||
filepath.Walk(container.RootfsPath(), func(path string, fileInfo os.FileInfo, err error) error {
|
||||
if fileInfo != nil {
|
||||
sizeRootfs += fileInfo.Size()
|
||||
|
|
41
image.go
41
image.go
|
@ -62,19 +62,27 @@ func LoadImage(root string) (*Image, error) {
|
|||
return img, nil
|
||||
}
|
||||
|
||||
func StoreImage(img *Image, jsonData []byte, layerData archive.Archive, root, rootfs string) error {
|
||||
func StoreImage(img *Image, jsonData []byte, layerData archive.Archive, root, layer string) error {
|
||||
// Store the layer
|
||||
layer := rootfs
|
||||
var (
|
||||
size int64
|
||||
err error
|
||||
driver = img.graph.driver
|
||||
)
|
||||
if err := os.MkdirAll(layer, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If layerData is not nil, unpack it into the new layer
|
||||
if layerData != nil {
|
||||
if differ, ok := img.graph.driver.(graphdriver.Differ); ok {
|
||||
if differ, ok := driver.(graphdriver.Differ); ok {
|
||||
if err := differ.ApplyDiff(img.ID, layerData); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if size, err = differ.DiffSize(img.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
start := time.Now()
|
||||
utils.Debugf("Start untar layer")
|
||||
|
@ -82,6 +90,24 @@ func StoreImage(img *Image, jsonData []byte, layerData archive.Archive, root, ro
|
|||
return err
|
||||
}
|
||||
utils.Debugf("Untar time: %vs", time.Now().Sub(start).Seconds())
|
||||
|
||||
if img.Parent == "" {
|
||||
if size, err = utils.TreeSize(layer); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
parent, err := driver.Get(img.Parent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
changes, err := archive.ChangesDirs(layer, parent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if size = archive.ChangesSize(layer, changes); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,18 +116,13 @@ func StoreImage(img *Image, jsonData []byte, layerData archive.Archive, root, ro
|
|||
return ioutil.WriteFile(jsonPath(root), jsonData, 0600)
|
||||
}
|
||||
// Otherwise, unmarshal the image
|
||||
jsonData, err := json.Marshal(img)
|
||||
if err != nil {
|
||||
if jsonData, err = json.Marshal(img); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ioutil.WriteFile(jsonPath(root), jsonData, 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
// Compute and save the size of the rootfs
|
||||
size, err := utils.TreeSize(rootfs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error computing size of rootfs %s: %s", img.ID, err)
|
||||
}
|
||||
|
||||
img.Size = size
|
||||
if err := img.SaveSize(root); err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue