daemon/graphdriver/btrfs: use filepath.WalkDir instead of filepath.Walk

WalkDir is more performant as it doesn't perform an os.Lstat on every visited
file or directory.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-10-09 17:04:16 +02:00
parent 1870d5f4aa
commit 8f1bc0bccc
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -269,7 +269,7 @@ func subvolDelete(dirpath, name string, quotaEnabled bool) error {
var args C.struct_btrfs_ioctl_vol_args
// walk the btrfs subvolumes
walkSubvolumes := func(p string, f os.FileInfo, err error) error {
walkSubVolumes := func(p string, f os.DirEntry, err error) error {
if err != nil {
if os.IsNotExist(err) && p != fullPath {
// missing most likely because the path was a subvolume that got removed in the previous iteration
@ -293,7 +293,7 @@ func subvolDelete(dirpath, name string, quotaEnabled bool) error {
}
return nil
}
if err := filepath.Walk(path.Join(dirpath, name), walkSubvolumes); err != nil {
if err := filepath.WalkDir(path.Join(dirpath, name), walkSubVolumes); err != nil {
return fmt.Errorf("Recursively walking subvolumes for %s failed: %v", dirpath, err)
}