Skip to content

Commit

Permalink
sort descendants by path len
Browse files Browse the repository at this point in the history
  • Loading branch information
hanagantig committed Jun 25, 2022
1 parent 51b1016 commit 95a0334
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions memmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ package afero

import (
"fmt"
"github.com/spf13/afero/mem"
"log"
"os"
"path/filepath"
"sort"
"strings"
"sync"
"time"

"github.com/spf13/afero/mem"
)

const chmodBits = os.ModePerm | os.ModeSetuid | os.ModeSetgid | os.ModeSticky // Only a subset of bits are allowed to be changed. Documented under os.Chmod()
Expand Down Expand Up @@ -98,7 +97,9 @@ func (m *MemMapFs) findDescendants(name string) []*mem.FileData {
}

sort.Slice(descendants, func(i, j int) bool {
return descendants[i].Name() < descendants[j].Name()
cur := len(strings.Split(descendants[i].Name(), FilePathSeparator))
next := len(strings.Split(descendants[j].Name(), FilePathSeparator))
return cur < next
})

return descendants
Expand Down

0 comments on commit 95a0334

Please sign in to comment.