From d106b294b428fbb10f59d4cafe72c3dcaa4e73bb Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Sat, 26 Mar 2022 06:39:11 -0400 Subject: 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 --- pkg/domain/infra/abi/system.go | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'pkg/domain/infra/abi') diff --git a/pkg/domain/infra/abi/system.go b/pkg/domain/infra/abi/system.go index d12d14c1f..4361821d5 100644 --- a/pkg/domain/infra/abi/system.go +++ b/pkg/domain/infra/abi/system.go @@ -6,7 +6,6 @@ import ( "net/url" "os" "os/exec" - "path/filepath" "github.com/containers/common/pkg/cgroups" "github.com/containers/common/pkg/config" @@ -269,7 +268,7 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System } dfVolumes := make([]*entities.SystemDfVolumeReport, 0, len(vols)) - var reclaimableSize int64 + var reclaimableSize uint64 for _, v := range vols { var consInUse int mountPoint, err := v.MountPoint() @@ -282,7 +281,7 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System // TODO: fix this. continue } - volSize, err := sizeOfPath(mountPoint) + volSize, err := util.SizeOfPath(mountPoint) if err != nil { return nil, err } @@ -301,8 +300,8 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System report := entities.SystemDfVolumeReport{ VolumeName: v.Name(), Links: consInUse, - Size: volSize, - ReclaimableSize: reclaimableSize, + Size: int64(volSize), + ReclaimableSize: int64(reclaimableSize), } dfVolumes = append(dfVolumes, &report) } @@ -313,19 +312,6 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System }, nil } -// 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 -func sizeOfPath(path string) (int64, error) { - var size int64 - err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error { - if err == nil && !info.IsDir() { - size += info.Size() - } - return err - }) - return size, err -} - func (se *SystemEngine) Reset(ctx context.Context) error { return se.Libpod.Reset(ctx) } -- cgit v1.2.3-54-g00ecf