2018-02-07 15:52:47 -05:00
|
|
|
package images
|
2018-02-21 17:16:57 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/image"
|
|
|
|
"github.com/docker/docker/layer"
|
|
|
|
"github.com/docker/docker/pkg/system"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2018-02-07 15:52:47 -05:00
|
|
|
// GetContainerLayerSize returns real size & virtual size
|
|
|
|
func (i *ImageService) GetContainerLayerSize(containerID string) (int64, int64) {
|
|
|
|
// TODO Windows
|
|
|
|
return 0, 0
|
|
|
|
}
|
|
|
|
|
2018-02-21 17:16:57 -05:00
|
|
|
// GetLayerFolders returns the layer folders from an image RootFS
|
2018-02-07 15:52:47 -05:00
|
|
|
func (i *ImageService) GetLayerFolders(img *image.Image, rwLayer layer.RWLayer) ([]string, error) {
|
2018-02-21 17:16:57 -05:00
|
|
|
folders := []string{}
|
|
|
|
max := len(img.RootFS.DiffIDs)
|
|
|
|
for index := 1; index <= max; index++ {
|
|
|
|
// FIXME: why does this mutate the RootFS?
|
|
|
|
img.RootFS.DiffIDs = img.RootFS.DiffIDs[:index]
|
|
|
|
if !system.IsOSSupported(img.OperatingSystem()) {
|
|
|
|
return nil, errors.Wrapf(system.ErrNotSupportedOperatingSystem, "cannot get layerpath for ImageID %s", img.RootFS.ChainID())
|
|
|
|
}
|
2021-03-19 10:34:08 -04:00
|
|
|
layerPath, err := layer.GetLayerPath(i.layerStore, img.RootFS.ChainID())
|
2018-02-21 17:16:57 -05:00
|
|
|
if err != nil {
|
2021-03-19 10:34:08 -04:00
|
|
|
return nil, errors.Wrapf(err, "failed to get layer path from graphdriver %s for ImageID %s", i.layerStore, img.RootFS.ChainID())
|
2018-02-21 17:16:57 -05:00
|
|
|
}
|
|
|
|
// Reverse order, expecting parent first
|
|
|
|
folders = append([]string{layerPath}, folders...)
|
|
|
|
}
|
|
|
|
if rwLayer == nil {
|
|
|
|
return nil, errors.New("RWLayer is unexpectedly nil")
|
|
|
|
}
|
|
|
|
m, err := rwLayer.Metadata()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to get layer metadata")
|
|
|
|
}
|
|
|
|
return append(folders, m["dir"]), nil
|
|
|
|
}
|