libpod/Container.rootFsSize(): use recorded image sizes

In rootFsSize(), instead of calculating the size of the diff for every
layer of the container's base image, ask the storage library for the sum
of the values it recorded when it first wrote those layers.

In a similar fashion, teach rwSize() to use the library's
ContainerSize() method instead of trying to roll its own.

Replace calls to pkg/util.SizeOfPath() with calls to
github.com/containers/storage/pkg/directory.Size(), which does the same
thing.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai
2023-05-08 13:47:28 -04:00
parent d49a537b8f
commit c400cc7ead
5 changed files with 37 additions and 63 deletions

View File

@ -3,7 +3,6 @@ package util
import (
"errors"
"fmt"
"io/fs"
"math"
"os"
"os/user"
@ -26,6 +25,7 @@ import (
"github.com/containers/podman/v4/pkg/namespaces"
"github.com/containers/podman/v4/pkg/rootless"
"github.com/containers/podman/v4/pkg/signal"
"github.com/containers/storage/pkg/directory"
"github.com/containers/storage/pkg/idtools"
stypes "github.com/containers/storage/types"
securejoin "github.com/cyphar/filepath-securejoin"
@ -618,19 +618,10 @@ func LookupUser(name string) (*user.User, error) {
// SizeOfPath determines the file usage of a given path. it was called volumeSize in v1
// and now is made to be generic and take a path instead of a libpod volume
// Deprecated: use github.com/containers/storage/pkg/directory.Size() instead.
func SizeOfPath(path string) (uint64, error) {
var size uint64
err := filepath.WalkDir(path, func(path string, d fs.DirEntry, err error) error {
if err == nil && !d.IsDir() {
info, err := d.Info()
if err != nil {
return err
}
size += uint64(info.Size())
}
return err
})
return size, err
size, err := directory.Size(path)
return uint64(size), err
}
// EncryptConfig translates encryptionKeys into a EncriptionsConfig structure