aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2022-03-26 06:39:11 -0400
committerMatthew Heon <mheon@redhat.com>2022-03-30 15:36:05 -0400
commitb362367efb7ecbe8aadeac3f5f4d5d17fe27862b (patch)
tree73ae0d46e7854d787c7d9b8fdfe9c8244f607ee6 /libpod
parent713ce2a96724e14a6a2acfcb93902826f0c4d2e2 (diff)
downloadpodman-b362367efb7ecbe8aadeac3f5f4d5d17fe27862b.tar.gz
podman-b362367efb7ecbe8aadeac3f5f4d5d17fe27862b.tar.bz2
podman-b362367efb7ecbe8aadeac3f5f4d5d17fe27862b.zip
Switch all calls to filepath.Walk to filepath.WalkDir
WalkDir should be faster the Walk, since we often do not need to stat files. [NO NEW TESTS NEEDED] Existing tests should find errors. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_internal.go11
-rw-r--r--libpod/volume.go12
2 files changed, 4 insertions, 19 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 0618cc02e..c2642f872 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -99,15 +99,8 @@ func (c *Container) rootFsSize() (int64, error) {
// rwSize gets the size of the mutable top layer of the container.
func (c *Container) rwSize() (int64, error) {
if c.config.Rootfs != "" {
- var size int64
- err := filepath.Walk(c.config.Rootfs, func(path string, info os.FileInfo, err error) error {
- if err != nil {
- return err
- }
- size += info.Size()
- return nil
- })
- return size, err
+ size, err := util.SizeOfPath(c.config.Rootfs)
+ return int64(size), err
}
container, err := c.runtime.store.Container(c.ID())
diff --git a/libpod/volume.go b/libpod/volume.go
index d60d978ed..2b263f9fb 100644
--- a/libpod/volume.go
+++ b/libpod/volume.go
@@ -1,13 +1,12 @@
package libpod
import (
- "os"
- "path/filepath"
"time"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/libpod/lock"
"github.com/containers/podman/v4/libpod/plugin"
+ "github.com/containers/podman/v4/pkg/util"
)
// Volume is a libpod named volume.
@@ -93,14 +92,7 @@ func (v *Volume) Name() string {
// Returns the size on disk of volume
func (v *Volume) Size() (uint64, error) {
- var size uint64
- err := filepath.Walk(v.config.MountPoint, func(path string, info os.FileInfo, err error) error {
- if err == nil && !info.IsDir() {
- size += (uint64)(info.Size())
- }
- return err
- })
- return size, err
+ return util.SizeOfPath(v.config.MountPoint)
}
// Driver retrieves the volume's driver.