From a00310b54c0cdcafb402aeea92feca865da9fdf3 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 24 Jan 2018 20:02:23 -0800 Subject: [PATCH] pkg/mount: use sort.Slice Sorting by mount point length can be implemented in a more straightforward fashion since Go 1.8 introduced sort.Slice() with an ability to provide a less() function in place. Signed-off-by: Kir Kolyshkin --- pkg/mount/mount.go | 4 +++- pkg/mount/mountinfo.go | 14 -------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/pkg/mount/mount.go b/pkg/mount/mount.go index 8ff4925d73..7bdbf8a837 100644 --- a/pkg/mount/mount.go +++ b/pkg/mount/mount.go @@ -72,7 +72,9 @@ func RecursiveUnmount(target string) error { } // Make the deepest mount be first - sort.Sort(sort.Reverse(byMountpoint(mounts))) + sort.Slice(mounts, func(i, j int) bool { + return len(mounts[i].Mountpoint) > len(mounts[j].Mountpoint) + }) for i, m := range mounts { if !strings.HasPrefix(m.Mountpoint, target) { diff --git a/pkg/mount/mountinfo.go b/pkg/mount/mountinfo.go index 05803938af..ecd03fc022 100644 --- a/pkg/mount/mountinfo.go +++ b/pkg/mount/mountinfo.go @@ -38,17 +38,3 @@ type Info struct { // VfsOpts represents per super block options. VfsOpts string } - -type byMountpoint []*Info - -func (by byMountpoint) Len() int { - return len(by) -} - -func (by byMountpoint) Less(i, j int) bool { - return by[i].Mountpoint < by[j].Mountpoint -} - -func (by byMountpoint) Swap(i, j int) { - by[i], by[j] = by[j], by[i] -}