Commit 74851f1f authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

newunionfs: make readdir deterministic

Change-Id: Ieba742bdbe830fdc18f82986694e2cd4d7caf161
parent 8cbe92c1
...@@ -346,18 +346,29 @@ func (n *unionFSNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) ...@@ -346,18 +346,29 @@ func (n *unionFSNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno)
// deepest root first. // deepest root first.
readRoot(root.roots[len(root.roots)-i-1], dir, names) readRoot(root.roots[len(root.roots)-i-1], dir, names)
} }
result := make([]fuse.DirEntry, 0, len(names)) result := make([]fuse.DirEntry, 0, 2*len(names))
maxIdx := -1
maxName := ""
for nm, mode := range names { for nm, mode := range names {
marker := filePathHash(filepath.Join(dir, nm)) marker := filePathHash(filepath.Join(dir, nm))
if _, ok := markers[marker]; ok { if _, ok := markers[marker]; ok {
continue continue
} }
if nm > maxName {
maxName = nm
maxIdx = len(result)
}
result = append(result, fuse.DirEntry{ result = append(result, fuse.DirEntry{
Name: nm, Name: nm,
Mode: mode, Mode: mode,
}) })
} }
if len(result) > 0 {
result = append(result[maxIdx:], result[:maxIdx]...)
}
return fs.NewListDirStream(result), 0 return fs.NewListDirStream(result), 0
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment