Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libimage: add LayersDiskUsage #1191

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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