mirror of
https://github.com/containers/podman.git
synced 2025-05-22 17:46:52 +08:00
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:
@ -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
|
||||
|
Reference in New Issue
Block a user