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 <kolyshkin@gmail.com>
| ... | ... |
@@ -72,7 +72,9 @@ func RecursiveUnmount(target string) error {
|
| 72 | 72 |
} |
| 73 | 73 |
|
| 74 | 74 |
// Make the deepest mount be first |
| 75 |
- sort.Sort(sort.Reverse(byMountpoint(mounts))) |
|
| 75 |
+ sort.Slice(mounts, func(i, j int) bool {
|
|
| 76 |
+ return len(mounts[i].Mountpoint) > len(mounts[j].Mountpoint) |
|
| 77 |
+ }) |
|
| 76 | 78 |
|
| 77 | 79 |
for i, m := range mounts {
|
| 78 | 80 |
if !strings.HasPrefix(m.Mountpoint, target) {
|
| ... | ... |
@@ -38,17 +38,3 @@ type Info struct {
|
| 38 | 38 |
// VfsOpts represents per super block options. |
| 39 | 39 |
VfsOpts string |
| 40 | 40 |
} |
| 41 |
- |
|
| 42 |
-type byMountpoint []*Info |
|
| 43 |
- |
|
| 44 |
-func (by byMountpoint) Len() int {
|
|
| 45 |
- return len(by) |
|
| 46 |
-} |
|
| 47 |
- |
|
| 48 |
-func (by byMountpoint) Less(i, j int) bool {
|
|
| 49 |
- return by[i].Mountpoint < by[j].Mountpoint |
|
| 50 |
-} |
|
| 51 |
- |
|
| 52 |
-func (by byMountpoint) Swap(i, j int) {
|
|
| 53 |
- by[i], by[j] = by[j], by[i] |
|
| 54 |
-} |