fsck: sort files alphabetically again

This makes fsck runs deterministic again.

Sorting (commit quoted below) got lost while
moving to go-fuse v2 api.

commit e6caf56ea4
Author: Jakob Unterwurzacher <jakobunt@gmail.com>
Date:   Mon Apr 2 16:56:29 2018 +0200

    fsck: sort files alphabetically

    This makes fsck runs deterministic.
This commit is contained in:
Jakob Unterwurzacher 2021-08-19 08:22:52 +02:00
parent 8ee595dd48
commit f3d927e590
1 changed files with 3 additions and 15 deletions

18
fsck.go
View File

@ -8,7 +8,7 @@ import (
"os"
"os/signal"
"path/filepath"
"strings"
"sort"
"sync"
"syscall"
@ -96,6 +96,8 @@ func (ck *fsckObj) dir(relPath string) {
ck.markCorrupt(relPath)
return
}
// Sort alphabetically to make fsck runs deterministic
sort.Strings(entries)
for _, entry := range entries {
if ck.abort {
return
@ -321,20 +323,6 @@ func fsck(args *argContainer) (exitcode int) {
return 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
}
func inum(f *os.File) uint64 {
var st syscall.Stat_t
err := syscall.Fstat(int(f.Fd()), &st)