Skip to content

Commit

Permalink
Merge pull request #1191 from vrothberg/fix-podman-16135
Browse files Browse the repository at this point in the history
libimage: add LayersDiskUsage
  • Loading branch information
openshift-merge-robot authored Oct 17, 2022
2 parents 40ed160 + 46db018 commit d8aaa54
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libimage/corrupted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func TestCorruptedLayers(t *testing.T) {
// Disk usage works.
_, err = runtime.DiskUsage(ctx)
require.NoError(t, err, "disk usage works on healthy image")
_, err = runtime.LayersDiskUsage(ctx)
require.NoError(t, err, "layers disk usage works on healthy image")

// Now remove one layer from the layers.json index in the storage. The
// image will still be listed in the container storage but attempting
Expand Down
15 changes: 15 additions & 0 deletions libimage/disk_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ import (
"time"
)

// LayersDiskUsage returns the sum of the size of all layers in the current store.
func (r *Runtime) LayersDiskUsage(ctx context.Context) (int64, error) {
layers, err := r.store.Layers()
if err != nil {
return -1, err
}

var size int64
for _, l := range layers {
size += l.UncompressedSize
}

return size, nil
}

// ImageDiskUsage reports the total size of an image. That is the size
type ImageDiskUsage struct {
// Number of containers using the image.
Expand Down

0 comments on commit d8aaa54

Please sign in to comment.