summaryrefslogtreecommitdiff
path: root/fsck.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-04-02 16:56:29 +0200
committerJakob Unterwurzacher2018-04-02 16:56:29 +0200
commite6caf56ea4ab10e747aa5dfc0a768cb8176ebe6a (patch)
tree5b1859e86df71e2b6ddf0f210a96644667ef70b5 /fsck.go
parentf28d85fad599ffaef9a8e1f353911c81a6605d2f (diff)
fsck: sort files alphabetically
This makes fsck runs deterministic.
Diffstat (limited to 'fsck.go')
-rw-r--r--fsck.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/fsck.go b/fsck.go
index 7741d19..32788e5 100644
--- a/fsck.go
+++ b/fsck.go
@@ -4,6 +4,8 @@ import (
"fmt"
"os"
"path/filepath"
+ "sort"
+ "strings"
"syscall"
"github.com/hanwen/go-fuse/fuse"
@@ -27,6 +29,8 @@ func (ck *fsckObj) dir(path string) {
ck.errorCount++
return
}
+ // Sort alphabetically
+ sort.Sort(sortableDirEntries(entries))
for _, entry := range entries {
if entry.Name == "." || entry.Name == ".." {
continue
@@ -102,3 +106,17 @@ func fsck(args *argContainer) {
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
+}