fsck: sort files alphabetically

This makes fsck runs deterministic.
This commit is contained in:
Jakob Unterwurzacher 2018-04-02 16:56:29 +02:00
parent f28d85fad5
commit e6caf56ea4

18
fsck.go
View File

@ -4,6 +4,8 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"sort"
"strings"
"syscall" "syscall"
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
@ -27,6 +29,8 @@ func (ck *fsckObj) dir(path string) {
ck.errorCount++ ck.errorCount++
return return
} }
// Sort alphabetically
sort.Sort(sortableDirEntries(entries))
for _, entry := range entries { for _, entry := range entries {
if entry.Name == "." || entry.Name == ".." { if entry.Name == "." || entry.Name == ".." {
continue continue
@ -102,3 +106,17 @@ func fsck(args *argContainer) {
os.Exit(exitcodes.FsckErrors) os.Exit(exitcodes.FsckErrors)
} }
} }
type sortableDirEntries []fuse.DirEntry
func (s sortableDirEntries) Len() int {
return len(s)
}
func (s sortableDirEntries) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s sortableDirEntries) Less(i, j int) bool {
return strings.Compare(s[i].Name, s[j].Name) < 0
}