mirror of
https://github.com/containers/podman.git
synced 2025-09-21 03:35:06 +08:00
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>
This commit is contained in:
@ -3,6 +3,7 @@ package util
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"math"
|
||||
"os"
|
||||
"os/user"
|
||||
@ -731,3 +732,20 @@ func LookupUser(name string) (*user.User, error) {
|
||||
}
|
||||
return user.Lookup(name)
|
||||
}
|
||||
|
||||
// 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) (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
|
||||
}
|
||||
|
Reference in New Issue
Block a user