osbuild: use path as secondary sort key for fstab
Most filesystems entries in fstab don't have a PassNo, which makes the order of those entries dependent on the sorting algorithm. Changes in the algorithm can introduce changes in the sort order, which we don't like. Add a secondary sorting key, the Path, which is guaranteed unique, to guarantee stable ordering.
This commit is contained in:
parent
e5d9d2d045
commit
c20e1e53c4
1 changed files with 6 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package osbuild
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/disk"
|
||||
|
|
@ -64,10 +65,14 @@ func NewFSTabStageOptions(pt *disk.PartitionTable) *FSTabStageOptions {
|
|||
return nil
|
||||
}
|
||||
|
||||
key := func(fs *FSTabEntry) string {
|
||||
return fmt.Sprintf("%d%s", fs.PassNo, fs.Path)
|
||||
}
|
||||
|
||||
_ = pt.ForEachMountable(genOption) // genOption always returns nil
|
||||
// sort the entries by PassNo to maintain backward compatibility
|
||||
sort.Slice(options.FileSystems, func(i, j int) bool {
|
||||
return options.FileSystems[i].PassNo < options.FileSystems[j].PassNo
|
||||
return key(options.FileSystems[i]) < key(options.FileSystems[j])
|
||||
})
|
||||
return &options
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue